/***************************************************************/
/*       CREATION D'UNE BASE DE DONNEES INITIALE CORRIGEE      */
/*                PRGM : BASE_INI_TRANSPO.SAS                  */
/***************************************************************/

DM 'CLEAR LOG; CLEAR OUTPUT;';
libname lect1 'W:\ACEMO\BASES_INITIALES\EC';
libname lect2 'W:\ACEMO\BASES_INITIALES\SAS7BDAT';
libname lect3 'W:\ACEMO\BASES_INITIALES\SD2';
libname lect4 'W:\ACEMO\BASES_INITIALES\DIVERSES';
libname lect5 'W:\ACEMO\PROJET_ACEMO\DONNEES\Donnees Regionales';
libname lect6 'W:\ACEMO\PROJET_ACEMO\DONNEES';
libname compl 'W:\ACEMO\PROJET_ACEMO\BASE_INITIALE\DONNEES_COMPL';
libname poids 'W:\ACEMO\PROJET_ACEMO\DONNEES\PONDERATIONS';
libname interm 'C:\Documents and Settings\l824468\Mes documents\WDN';
libname ipcreg 'W:\ACEMO\PROJET_ACEMO\resultats\IPC';
libname lect7 'W:\ACEMO\PROJET_ACEMO\DONNEES\Donnees Regionales\IPC';
libname ecriture 'W:\ACEMO\PROJET_ACEMO\BASE_INITIALE';
options linesize = 100;
options pagesize = 72;

/******************************************************************************/
/************            I - LECTURE DES FICHIERS INITIAUX       **************/
/******************************************************************************/

/******************************************************************************/
/* PROC CONTENTS DES FICHIERS DEZIPPES                                        */
/* ATTENTION : IL EST DIFFICILE DE FUSIONNER TOUS LES FICHIERS TELS QUELS     */
/* CAR, SUIVANT LES FICHIERS, CERTAINES VARIABLES SONT DEFINIES EN NUMERIQUE  */
/* ET EN ALPHANUMERIQUE                                                       */ 
/******************************************************************************/
/*
proc contents data=lect2.pro19991 short;run;
proc contents data=lect2.pro19992 short;run;
proc contents data=lect2.pro19993 short;run;
proc contents data=lect2.pro19994 short;run;

proc contents data=lect3.pro20001 short;run;
proc contents data=lect2.pro20002 short;run;
proc contents data=lect2.pro20003 short;run;
proc contents data=lect2.pro20004 short;run;

proc contents data=lect2.pro20011 short;run;
proc contents data=lect3.pro20012 short;run;
proc contents data=lect3.pro20013 short;run;
proc contents data=lect3.pro20014 short;run;

proc contents data=lect2.pro20021 short;run;
proc contents data=lect2.pro20022 short;run;
proc contents data=lect2.pro20023 short;run;
proc contents data=lect2.pro20024 short;run;

proc contents data=lect2.pro20031 short;run;
proc contents data=lect2.pro20032 short;run;
proc contents data=lect2.pro20033 short;run;
proc contents data=lect2.pro20034 short;run;

proc contents data=lect2.pro20041 short;run;
proc contents data=lect2.pro20042 short;run;
proc contents data=lect2.pro20043_resultats short;run;
proc contents data=lect2.pro20044_resultats short;run;

proc contents data=lect2.pro20051_resultats short;run;
proc contents data=lect2.pro20052_resultats short;run;
proc contents data=lect2.pro20053_resultats short;run;
proc contents data=lect2.pro20054_resultats short;run;

proc contents data=lect2.pro20061_resultats  short;run;
*/


/**********************************************/
/* ON RENOMME LA VARIABLE EFFU EN EFFSIR      */
/* ON RENOMME LA VARIABLE APE  EN C_APETD     */
/**********************************************/
data ecriture.pro20061_resultats;set lect2.pro20061_resultats;
rename effu=EFFSIR;rename ape=C_APETD;rename tailent=C_TEFEND;
run;

/**********************************************/
/* EMPILEMENT DES FICHIERS ACEMO 1999 - 2006  */
/* CREATION DE ACEMO_1996_2005_EXTRACT        */
/* SELECTION DES VARIABLES DONT ON A BESOIN   */
/* AVANT DE SUPPRIMER LES DOUBLONS            */
/* CREATION DE LA VARIABLE 'DATE' :           */
/* aaaa.00 : 1er trimestre                    */
/* aaaa.25 : 2�me trimestre                   */
/* aaaa.50 : 3�me trimestre                   */
/* aaaa.75 : 4�me trimestre                   */
/**********************************************/
data ecriture.ACEMO_1999_2006_extract; set 

/*1999*/
lect2.pro19991          (in=DS19991 keep=
SIRET EFFTOT EFFSIR 
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)/* manquent NICGR N16 N36 */
lect2.pro19992			(in=DS19992 keep=
SIRET EFFTOT 
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)/* manquent EFFSIR NICGR */
lect2.pro19993			(in=DS19993 keep=
SIRET EFFTOT EFFSIR
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)/* manque NICGR  */
lect2.pro19994		(in=DS19994 keep=
SIRET EFFTOT EFFSIR   
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)/* manque NICGR  */ 

/*2000*/
lect3.pro20001			 (in=DS20001 keep=
SIRET EFFTOT EFFSIR NICGR
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
) 
lect2.pro20002		(in=DS20002 keep=
SIRET EFFTOT EFFSIR NICGR  
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
) 
lect2.pro20003		(in=DS20003 keep=
SIRET EFFTOT EFFSIR NICGR  
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
) 
lect2.pro20004		(in=DS20004 keep=
SIRET EFFTOT NICGR  
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)/* manque EFFSIR */ 

/*2001*/
lect2.pro20011		(in=DS20011 keep=
SIRET EFFTOT EFFSIR NICGR   
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
) 
lect3.pro20012			(in=DS20012 keep=
SIRET EFFTOT EFFSIR NICGR 
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
) 
lect3.pro20013			(in=DS20013 keep=
SIRET EFFTOT EFFSIR NICGR 
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
) 
lect3.pro20014			(in=DS20014 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)

/*2002*/
lect2.pro20021			(in=DS20021 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20022			(in=DS20022 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20023			(in=DS20023 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20024			(in=DS20024 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)

/*2003*/
lect2.pro20031			(in=DS20031 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20032			(in=DS20032 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20033			(in=DS20033 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20034			(in=DS20034 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)

/*2004*/
lect2.pro20041			(in=DS20041 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20042			(in=DS20042 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20043_resultats(in=DS20043 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20044_resultats(in=DS20044 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)

/*2005*/
lect2.pro20051_resultats(in=DS20051 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
) /* attention, ds le fichier zipp�, il ya un accent en trop � "r�sultats" */
lect2.pro20052_resultats(in=DS20052 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20053_resultats(in=DS20053 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)
lect2.pro20054_resultats(in=DS20054 keep=
SIRET EFFTOT EFFSIR NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36 C_APETD R_RETOUR PREST1 S_ET C_TEFEND
)

/*2006*/
ecriture.pro20061_resultats(in=DS20061 keep=
SIRET EFFTOT EFFSIR  NICGR DATESAI
HORM01 HORM02 HORM03 HORM04 HORM05 HORM06 HORM07 HORM08 HORM09 HORM10 HORM11 HORM12
SALM01 SALM02 SALM03 SALM04 SALM05 SALM06 SALM07 SALM08 SALM09 SALM10 SALM11 SALM12
HORM011 HORM021 HORM031 HORM041 HORM051 HORM061 HORM071 HORM081 HORM091 HORM101 HORM111 HORM121
SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 SALM091 SALM101 SALM111 SALM121
N16 N36  R_RETOUR C_APETD PREST1 S_ET C_TEFEND
) /* APE renomm� en C_APETD */
 /* effu renomm� en EFFSIR */
;

format DATE best12.;
if DS19991 then DATE = 1998.75; 
if DS19992 then DATE = 1999.00; 
if DS19993 then DATE = 1999.25; 
if DS19994 then DATE = 1999.50;

if DS20001 then DATE = 1999.75; 
if DS20002 then DATE = 2000.00; 
if DS20003 then DATE = 2000.25; 
if DS20004 then DATE = 2000.50; 

if DS20011 then DATE = 2000.75;
if DS20012 then DATE = 2001.00; 
if DS20013 then DATE = 2001.25; 
if DS20014 then DATE = 2001.50; 

if DS20021 then DATE = 2001.75; 
if DS20022 then DATE = 2002.00; 
if DS20023 then DATE = 2002.25; 
if DS20024 then DATE = 2002.50; 

if DS20031 then DATE = 2002.75; 
if DS20032 then DATE = 2003.00; 
if DS20033 then DATE = 2003.25; 
if DS20034 then DATE = 2003.50; 

if DS20041 then DATE = 2003.75; 
if DS20042 then DATE = 2004.00; 
if DS20043 then DATE = 2004.25; 
if DS20044 then DATE = 2004.50; 

if DS20051 then DATE = 2004.75; 
if DS20052 then DATE = 2005.00; 
if DS20053 then DATE = 2005.25; 
if DS20054 then DATE = 2005.50; 

if DS20061 then DATE = 2005.75; 

rename s_et = numero;run;

run;
proc contents data=ecriture.ACEMO_1999_2006_extract;run;



/****************************************************************************************/
/************            II - CORRECTIONS DE LA BASE BRUTE           ********************/
/****************************************************************************************/ 



/***********************************************/
/* SUPPRESSION DE 50 OBS. DONT LE SIRET = '  ' */ 
/* CAR INUTILES                                */
/* ON SUPPRIME 12 SIRET BIZARRES               */
/* ON RENOMME 2 SIRET                          */
/* TOTAL 62 OBS. SUPPRIMEES                    */
 /***********************************************/
data ecriture.ACEMO_1999_2006_extract2; set ecriture.ACEMO_1999_2006_extract;
if siret =  '    ' then delete;
if siret = '*0130960500410' then delete;
if siret = '*0146545600020' then delete;
if siret = '*0212489500010' then delete;
if siret = '*3205019100055' then delete;
if siret = '*4537056300099' then delete;
if siret = '*5208131766522' then delete;
if siret = '*7563413200242' then delete;
if siret = '*8316034800041' then delete;
if siret = '+7935959500021' then delete;
if siret = '.0374248000013' then delete;
if siret = 'AS153070900111' then delete;
if siret = 'ISON ESTIVALE9' then delete;
if siret = '$5780615000017' then siret = '05780615000017';                                           
if siret = '*6150024500016' then siret = '06150024500016';     
run;
proc contents data=ecriture.ACEMO_1999_2006_extract2;run;
proc sort data = ecriture.ACEMO_1999_2006_extract2; by SIRET DATE; run;

/***************************************/
/* RECHERCHE DES DOUBLONS              */
/***************************************/
/* DOUBLONS PAR SIRET DATE */
/* 36 obs. en doublon soit 72 obs. */
/* tri effectu� juste au dessus ! */
/*proc sort data = ecriture.ACEMO_1999_2006_extract2; by SIRET DATE; run;*/
proc means data = ecriture.ACEMO_1999_2006_extract2 noprint; by SIRET DATE; var DATE;
output out = TEST n = NBRANCHES; run;
proc sort data = TEST; by NBRANCHES SIRET DATE; run;
proc sort data = TEST(where = (NBRANCHES>1)) out = TEST2;
by SIRET DATE; run; 
data TEST3; merge TEST2(in=DSTEST2) ecriture.ACEMO_1999_2006_extract2;
by SIRET DATE; if DSTEST2; run;
proc print data=TEST3;run;

/* la suppression de la variable DATESAI permet de mettre en �vidence les doublons dus � cette
   variable "inutile" */
/* et donc de supprimer 32 observations / 72 observations (17+15=32)*/
/* restent 40 observations � �tudier dans lesquelles certaines ont efftot = .  */
data TEST4; set test3; drop datesai;run;
proc sort data = TEST4 out = TEST5 noduprecs; by SIRET DATE; run;
proc print data=TEST5;run;

/* y a t-il encore doublons ? */
/* oui pour un m�me "siret date", on a 2 lignes dont seule la variable efftot est diff�rente :
   sur une ligne efftot est aliment�e, sur l'autre elle vaut . : 4 obs.*/ 
proc means data = test5 noprint; by SIRET DATE; var DATE;
output out = TEST6 n = NBRANCHES; run;
proc sort data = TEST6; by NBRANCHES SIRET DATE; run;
proc sort data = TEST6(where = (NBRANCHES>1)) out = TEST7;
by SIRET DATE; run; 
proc print data=TEST7;run;

/* on fusionne les 4 obs. avec le fichier complet pour avoir toutes les infos. : 8 obs. */
/* inutile ? */
data TEST8; merge TEST7(in=DSTEST7) ecriture.ACEMO_1999_2006_extract2;
by SIRET DATE; if DSTEST7; run;
proc print data=TEST8;run;

/***************************************/
/* SUPPRESSION DES DOUBLONS            */
/* CREATION DE ACEMO_1996_2005_APURE   */
/* CREATION DE ACEMO_1996_2005_APURE2  */
/* QUI NE CONTIENT PLUS DE DOUBLONS    */
/* SIRET / DATE                        */
/***************************************/
/* DOUBLONS PAR SIRET DATE */
/* on supprime la variable DATESAI car cause de nombreux doublons et variable "inutile" */
data ecriture.ACEMO_1999_2006_apure; set ecriture.ACEMO_1999_2006_extract2; drop datesai;run;
proc contents data=ecriture.ACEMO_1999_2006_apure;run;
/* ON SUPPRIME LES DOUBLONS "PARFAITS" SIRET DATE :
   32 obs. en double supprim�es */
proc sort data = ecriture.ACEMO_1999_2006_apure out = ecriture.ACEMO_1999_2006_apure noduprecs;
by SIRET DATE; run;
proc contents data=ecriture.ACEMO_1999_2006_apure;run;

/* on r�cup�re de test8 la liste des obs. en double et dont efftot ne . */
/* lignes de prg de Thomas*/
/* on peut tout aussi bien repartir de test7 en supprimant TYPE FREQ NBBRANCHES*/
data test9(drop = efftot); set test8(keep = siret date efftot where=(efftot ne .)); run; 

/* ON SUPPRIME 4 OBS. DONT EFFTOT = . */
data ecriture.ACEMO_1999_2006_apure2;
merge ecriture.ACEMO_1999_2006_apure test9(in=DSTEST9);by siret date; 
if DSTEST9 and efftot = . then delete;run;
proc contents data=ecriture.ACEMO_1999_2006_apure2;run;

/* v�rification de la suppression des 36 doublons */
proc sort data = ecriture.ACEMO_1999_2006_apure2
out = ACEMO_1999_2006_apure3 noduprecs; by SIRET DATE; run;
proc sort data = ecriture.ACEMO_1999_2006_apure2 
out = ACEMO_1999_2006_apure3 nodupkeys ; by SIRET DATE; run;



/**************************************************/
/* CORRECTION DE L'EURO POUR LES SALAIRES         */
/* EN FRANC JUSQU'EN 2001.5 INCLUS                */
/* EN EUROS A PARTIR DE 2001.75                   */
/* ON CONVERTIT LES SALAIRES EN EUROS             */ 
/* LES VARIABLES CONVERTIES ONT UN "E" A LA FIN   */
/* CREATION DE ecriture.ACEMO_1999_2006_apure3    */
/* AVEC SALAIRES CONVERTIS EN EUROS               */
/**************************************************/

proc sort data = ecriture.ACEMO_1999_2006_apure2 
out = ecriture.ACEMO_1999_2006_apure2 ; by SIRET DATE; run;

/* macro de conversion en euro - arrondi � l'unit� */
%macro euro(nom1,nom2);
format &nom1 best12. ;
A&nom1=&nom2;
B&nom1=round(&nom2/6.55957);
&nom1=A&nom1;
if date le 2001.5 then &nom1=B&nom1;
drop A&nom1 B&nom1;
%MEND euro ;
data ecriture.ACEMO_1999_2006_apure3; set ecriture.ACEMO_1999_2006_apure2;
%euro(SALM01E,SALM01);%euro(SALM02E,SALM02);%euro(SALM03E,SALM03);
%euro(SALM04E,SALM04);%euro(SALM05E,SALM05);%euro(SALM06E,SALM06);
%euro(SALM07E,SALM07);%euro(SALM08E,SALM08);%euro(SALM09E,SALM09);
%euro(SALM10E,SALM10);%euro(SALM11E,SALM11);%euro(SALM12E,SALM12);
%euro(SALM011E,SALM011);%euro(SALM021E,SALM021);%euro(SALM031E,SALM031);
%euro(SALM041E,SALM041);%euro(SALM051E,SALM051);%euro(SALM061E,SALM061);
%euro(SALM071E,SALM071);%euro(SALM081E,SALM081);%euro(SALM091E,SALM091);
%euro(SALM101E,SALM101);%euro(SALM111E,SALM111);%euro(SALM121E,SALM121);
run;

proc contents data=ecriture.ACEMO_1999_2006_apure3;run;


/******************************************************/
/* CORRECTION DES C_APETD MANQUANTS A CERTAINES DATES */
/* ON AFFECTE LE CODE APE TROUV� AUX AUTRES DATES     */
/* ON AFFECTE LE CODE APE DE L'INSEE SINON            */
/* 3 siret-date sans c_apetd                          */
/******************************************************/
data ecriture.ACEMO_cor_ape; set ecriture.ACEMO_1999_2006_apure3;
if siret ='30207946200206' and date =1999.25 then c_apetd='157C';
if siret ='30207946200206' and date =1999.5 then c_apetd='157C';
if siret ='30483835200108' and date =1999.5 then c_apetd='742C';
if siret ='30585064600038' and date =1999.5 then c_apetd='452B';
if siret ='30673362700088' and date =1999.25 then c_apetd='721Z';
if siret ='30673362700088' and date =1999.5 then c_apetd='721Z';
if siret ='30956656000038' and date =1999.25 then c_apetd='741C';
if siret ='30956656000038' and date =1999.5 then c_apetd='741C';
if siret ='31071022300234' and date =2001.75 then c_apetd='521D';
if siret ='31391576100040' and date =1999.5 then c_apetd='174B';
if siret ='31950563200087' and date =1999.5 then c_apetd='711Z';
if siret ='32018093800070' and date =1999 then c_apetd='602P';
if siret ='32018093800070' and date =1999.25 then c_apetd='602P';
if siret ='32018093800070' and date =1999.5 then c_apetd='602P';
if siret ='32054391100012' and date =1999 then c_apetd='703C';
if siret ='32054391100012' and date =1999.25 then c_apetd='703C';
if siret ='32054391100012' and date =1999.5 then c_apetd='703C';
if siret ='32375113100059' and date =1999.25 then c_apetd='511N';
if siret ='32375113100059' and date =1999.5 then c_apetd='511N';
if siret ='32639865800038' and date =1999.25 then c_apetd='722';
if siret ='32639865800038' and date =1999.5 then c_apetd='722';
if siret ='32954339100042' and date =2001.75 then c_apetd='746Z';
if siret ='32987025700048' and date =1999.5 then c_apetd='748F';
if siret ='33286446100089' and date =1999.25 then c_apetd='722Z';
if siret ='33286446100089' and date =1999.5 then c_apetd='722Z';
if siret ='33980986500035' and date =2000.5 then c_apetd='452V';
if siret ='34210012000050' and date =2001.75 then c_apetd='286A';
if siret ='34241853000040' and date =1999.5 then c_apetd='513W';
if siret ='34296650400017' and date =1999.25 then c_apetd='513D';
if siret ='34296650400017' and date =1999.5 then c_apetd='513D';
if siret ='34513051200287' and date =1999 then c_apetd='513W';
if siret ='34513051200287' and date =1999.25 then c_apetd='513W';
if siret ='34513051200287' and date =1999.5 then c_apetd='513W';
if siret ='34513051201509' and date =1999 then c_apetd='513W';
if siret ='34513051201509' and date =1999.25 then c_apetd='513W';
if siret ='34513051201509' and date =1999.5 then c_apetd='513W';
if siret ='34513051201756' and date =1999 then c_apetd='513W';
if siret ='34513051201756' and date =1999.25 then c_apetd='513W';
if siret ='34513051201756' and date =1999.5 then c_apetd='513W';
if siret ='34513051201913' and date =1999 then c_apetd='513W';
if siret ='34513051201913' and date =1999.25 then c_apetd='513W';
if siret ='34513051201913' and date =1999.5 then c_apetd='513W';
if siret ='34823276000010' and date =1999.25 then c_apetd='553B';
if siret ='34823276000010' and date =1999.5 then c_apetd='553B';
if siret ='34895031200010' and date =2000.5 then c_apetd='551A';
if siret ='35292174600025' and date =1999 then c_apetd='292C';
if siret ='35292174600025' and date =1999.25 then c_apetd='292C';
if siret ='35292174600025' and date =1999.5 then c_apetd='292C';
if siret ='35480056700332' and date =1999.25 then c_apetd='515C';
if siret ='37826684500064' and date =1999.5 then c_apetd='731Z';
if siret ='37830497600046' and date =1999.25 then c_apetd='454D';
if siret ='37830497600046' and date =1999.5 then c_apetd='454D';
if siret ='38013296900029' and date =1999.5 then c_apetd='748K';
if siret ='38023289200022' and date =1999 then c_apetd='343Z';
if siret ='38023289200022' and date =1999.25 then c_apetd='343Z';
if siret ='38023289200022' and date =1999.5 then c_apetd='343Z';
if siret ='38466364700038' and date =1999.5 then c_apetd='514L';
if siret ='38505616300012' and date =1999 then c_apetd='452L';
if siret ='38505616300012' and date =1999.25 then c_apetd='452L';
if siret ='38505616300012' and date =1999.5 then c_apetd='452L';
if siret ='39393231400031' and date =1999.25 then c_apetd='851A';
*if siret ='39722007000163' and date =1999 then c_apetd='?';
*if siret ='39722007000163' and date =1999.25 then c_apetd='?';
*if siret ='39722007000163' and date =1999.5 then c_apetd='?';
if siret ='39893668200028' and date =1999 then c_apetd='452P';
if siret ='39893668200028' and date =1999.25 then c_apetd='452P';
if siret ='39893668200028' and date =1999.5 then c_apetd='452P';
if siret ='40031845700019' and date =1999 then c_apetd='521D';
if siret ='40031845700019' and date =1999.25 then c_apetd='521D';
if siret ='40031845700019' and date =1999.5 then c_apetd='521D';
if siret ='40082527900021' and date =2000.5 then c_apetd='524Z';
if siret ='40214192300035' and date =2000.5 then c_apetd='521J';
if siret ='40252131400136' and date =1999.5 then c_apetd='158F';
if siret ='40286353400101' and date =1999 then c_apetd='514N';
if siret ='40286353400101' and date =1999.25 then c_apetd='514N';
if siret ='40286353400101' and date =1999.5 then c_apetd='514N';
if siret ='40532664600040' and date =1999.5 then c_apetd='742C';
if siret ='40957034800030' and date =1999.5 then c_apetd='453A';
if siret ='41040921300056' and date =1999 then c_apetd='521F';
if siret ='41040921300056' and date =1999.25 then c_apetd='521F';
if siret ='41040921300056' and date =1999.5 then c_apetd='521F';
if siret ='41040946000871' and date =1999.25 then c_apetd='521F';
if siret ='41040946001150' and date =1999.25 then c_apetd='521F';
if siret ='41040946001150' and date =1999.5 then c_apetd='521F';
if siret ='41040946001325' and date =1999.25 then c_apetd='521F';
if siret ='41040946001325' and date =1999.5 then c_apetd='521F';
if siret ='41492167600014' and date =1999 then c_apetd='285D';
if siret ='41492167600014' and date =1999.25 then c_apetd='285D';
if siret ='41492167600014' and date =1999.5 then c_apetd='285D';
if siret ='41504931100012' and date =1999.25 then c_apetd='911A';
if siret ='41504931100020' and date =1999.5 then c_apetd='911A';
if siret ='41957593100078' and date =1999.25 then c_apetd='524N';
if siret ='41957593100078' and date =1999.5 then c_apetd='524N';
if siret ='42054064300038' and date =1999.5 then c_apetd='453A';
if siret ='42054180700020' and date =1999.5 then c_apetd='453A';
if siret ='42054201100036' and date =1999.5 then c_apetd='453A';
if siret ='42117403800032' and date =2002.75 then c_apetd='271Z';
if siret ='42119529800011' and date =1999.5 then c_apetd='361G';
if siret ='42121813200148' and date =1999.5 then c_apetd='514N';
if siret ='42138945300026' and date =1999.25 then c_apetd='501Z';
if siret ='42138945300026' and date =1999.5 then c_apetd='501Z';
if siret ='42241013400015' and date =1999.5 then c_apetd='551A';
if siret ='42243506500012' and date =1999.5 then c_apetd='274K';
if siret ='42243808500017' and date =1999.25 then c_apetd='361M';
if siret ='42243808500017' and date =1999.5 then c_apetd='361M';
if siret ='42300198100012' and date =1999.5 then c_apetd='175E';
if siret ='42469104600017' and date =2002.75 then c_apetd='401Z';
if siret ='43393888300025' and date =2001.75 then c_apetd='251A';
if siret ='43396258600015' and date =2002 then c_apetd='742C';
if siret ='43396258600015' and date =2002.25 then c_apetd='742C';
if siret ='43399847300014' and date =2001.75 then c_apetd='742C';
if siret ='53542053300312' and date =1999.5 then c_apetd='514N';
if siret ='54200899000195' and date =1999.5 then c_apetd='343Z';
if siret ='54206547900314' and date =2002.75 then c_apetd='341Z';
if siret ='54207843100294' and date =1999 then c_apetd='633Z';
if siret ='54207843100294' and date =1999.25 then c_apetd='633Z';
if siret ='54207843100294' and date =1999.5 then c_apetd='633Z';
if siret ='54655029400013' and date =1999 then c_apetd='182E';
if siret ='54655029400013' and date =1999.25 then c_apetd='182E';
if siret ='54655029400013' and date =1999.5 then c_apetd='182E';
if siret ='55201198300640' and date =1999.25 then c_apetd='634A';
if siret ='55201198300640' and date =1999.5 then c_apetd='634A';
if siret ='56208290900895' and date =1999.25 then c_apetd='322B';
if siret ='56208290900895' and date =1999.5 then c_apetd='322B';
if siret ='66201448900360' and date =1999.25 then c_apetd='900B';
if siret ='66201448900360' and date =1999.5 then c_apetd='900B';
if siret ='68201007900700' and date =2001.75 then c_apetd='631B';
if siret ='70201246900061' and date =2000.5 then c_apetd='745A';
if siret ='76120085600018' and date =1999.5 then c_apetd='286D';
if siret ='77573383500869' and date =1999.5 then c_apetd='714A';
if siret ='77895071700265' and date =2001.75 then c_apetd='853D';
if siret ='78462262300048' and date =1999 then c_apetd='672Z';
if siret ='78462262300048' and date =1999.25 then c_apetd='672Z';
if siret ='78462262300048' and date =1999.5 then c_apetd='672Z';
if siret ='78826165900072' and date =1999.5 then c_apetd='513W';
if siret ='85680240000361' and date =1999.5 then c_apetd='515A';
if siret ='97250441903452' and date =2002.75 then c_apetd='747Z';
/* correction de l'ape 813B en 853B */
if siret ='37892515000070' and date =2001.5 then c_apetd='853B';
run;


/******************************************************/
/* ON CREE LA VARIABLE NES16 CAR                      */
/* LA SERIE N16 EST MAL AFFECTEE AUX DATES SUIVANTES :*/
/* 2000.75, 2001.75, 2002, 2002.25, et 2002.5         */
/* TABLE DE CORRESPONDANCE APE - NES16                */
/******************************************************/
data ecriture.ACEMO_nes16; set ecriture.ACEMO_cor_ape;
format NES16 $2. ; 
if c_apetd = '    ' then NES16 = '  ';
if substr(c_apetd,1,2) in ('01','02','05') then NES16 = 'EA';
if substr(c_apetd,1,2) in ('15','16') then NES16 = 'EB';
if substr(c_apetd,1,2) in ('18','19','22','36') then NES16 = 'EC';
if substr(c_apetd,1,3) in ('244','245','297','323','334','335') then NES16 = 'EC';
if substr(c_apetd,1,2) in ('34') then NES16 = 'ED';
if substr(c_apetd,1,2) in ('30','35') then NES16 = 'EE';
if substr(c_apetd,1,3) in 
('281','282','283','291','292','293','294','295','296','311','322','331','332','333')
then NES16 = 'EE';
if substr(c_apetd,1,2) in ('13','14','17','20','21','25','26','27','37') then NES16 = 'EF';
if substr(c_apetd,1,3) in 
('241','242','243','246','247','284','285','286','287','312','313','314','315','316','321')
then NES16 = 'EF';
if substr(c_apetd,1,2) in ('10','11','12','23','40','41') then NES16 = 'EG';
if substr(c_apetd,1,2) in ('45') then NES16 = 'EH';
if substr(c_apetd,1,2) in ('50','51','52') then NES16 = 'EJ';
if substr(c_apetd,1,2) in ('60','61','62','63') then NES16 = 'EK';
if substr(c_apetd,1,2) in ('65','66','67') then NES16 = 'EL';
if substr(c_apetd,1,2) in ('70') then NES16 = 'EM';
if substr(c_apetd,1,2) in ('64','71','72','73','74','90') then NES16 = 'EN';
if substr(c_apetd,1,2) in ('55','92','93','95','96','97') then NES16 = 'EP';
if substr(c_apetd,1,2) in ('80','85') then NES16 = 'EQ';
if substr(c_apetd,1,2) in ('75','91','99') then NES16 = 'ER';
run;

proc contents data=ecriture.ACEMO_nes16;run;




/*************************************************************************************/
/**********************     III - INTEGRATION DES POIDS       ************************/
/*************************************************************************************/


/* fichier ACTTABU5.SAS7BDAT (sur w:\acemo\projet_acemo\donnees\ponderations)        */
/* issu du prgm POIDS_29SEPT06.SAS                                                   */
/*************************************************************************************/



proc sort data=ecriture.ACEMO_nes16;by numero date;run;
proc sort data=poids.acttabu5 out=ecriture.acttabu5;by numero date_poids;run;

/*data verif;set ecriture.acttabu5 (where=(numero = .));run;*//* 0 obs avec NUMERO=. */
/*
proc contents data=ecriture.ACEMO_nes16;run;
proc contents data=ecriture.acttabu5;run;
*/

data ecriture.ponderations;set ecriture.acttabu5;
date=date_poids-0.25;
drop  C_APETD C_TEFEND EFFTOT PREST1 SALM01-SALM12 SALM011 SALM021 SALM031 SALM041 SALM051 SALM061 SALM071 SALM081 
SALM091 SALM101 SALM111 SALM121 ;
run;

proc contents data=ecriture.ponderations;run;

data ecriture.ACEMO_poids;
merge	ecriture.ACEMO_nes16 (in=in1)
		ecriture.ponderations;
if in1;
by numero date;
run;
 /*
data verif1;set ecriture.acemo_poids (where=(siret='00548054600018'));  
keep siret date date_poids numero c_tefend c_apetd prest1 efftot salm01-salm12 pcatEntSect01-pcatEntSect12;run; 
data verif2;set ecriture.acemo_nes16 (where=(siret='00548054600018'));
keep siret date numero c_tefend c_apetd prest1 efftot salm01-salm12;run; 
data verif3;set ecriture.acttabu5 (where=(numero=2));
keep numero date date_poids c_tefend c_apetd prest1 efftot salm01-salm12 pcatEntSect01-pcatEntSect12;run; 

data verif4;set ecriture.acemo_poids (where=(siret='30998674300016'));  
keep siret date date_poids numero c_tefend c_apetd prest1 efftot salm01-salm12 pcatEntSect01-pcatEntSect12;run; 
data verif5;set ecriture.acemo_nes16 (where=(siret='30998674300016'));
keep siret date numero c_tefend c_apetd prest1 efftot salm01-salm12;run; 
data verif6;set ecriture.acttabu5 (where=(numero=136076));
keep numero date date_poids c_tefend c_apetd prest1 efftot salm01-salm12 pcatEntSect01-pcatEntSect12;run; 
*/

proc contents data=ecriture.ACEMO_poids;run;



/**************************************************************************************/
/**********************         IV - SALAIRE HORAIRE           ************************/
/**************************************************************************************/ 



/******************************************************/
/* CALCUL D'UN SALAIRE HORAIRE POUR LES 12 CATEGORIES */
/* ATTENTION !                                        */
/* LE LAG DES SALAIRES ET HORAIRES EST DEJA CALCULE   */
/* ON SUPPOSE QUE LE LAG N'EXISTE QUE POUR UN MEME    */
/* SIRET A DES DATES QUI SE SUIVENT                   */
/* APRES VERIF. CELA SEMBLE ETRE LE CAS...            */               
/* ATTENTION AUX VALEURS EXTREMES DES VARIABLES !     */ 
/* LES VALEURS DE SALHORXX EGALES A 0 OU .            */
/* SONT REPEREES PAR INDICxx=1                        */
/* LES VALEURS DE LSALHORXX EGALES A 0 OU .           */
/* SONT REPEREES PAR LINDICxx=1                       */
/******************************************************/
/* tri par SIRET DATE */
proc sort data=ecriture.ACEMO_poids; by SIRET DATE; run;

/* calcul du salaire horaire � la date T */
data ecriture.ACEMO_salhor;set ecriture.ACEMO_poids;
salhor01=SALM01E/HORM01;salhor02=SALM02E/HORM02;salhor03=SALM03E/HORM03;
salhor04=SALM04E/HORM04;salhor05=SALM05E/HORM05;salhor06=SALM06E/HORM06;
salhor07=SALM07E/HORM07;salhor08=SALM08E/HORM08;salhor09=SALM09E/HORM09;
salhor10=SALM10E/HORM10;salhor11=SALM11E/HORM11;salhor12=SALM12E/HORM12;
indichor01=0;indichor02=0;indichor03=0;indichor04=0;indichor05=0;indichor06=0;
indichor07=0;indichor08=0;indichor09=0;indichor10=0;indichor11=0;indichor12=0;
/* calcul du salaire horaire � la date T-1 : on utilise les s�ries cr��es dans ACEMO */
lsalhor01=SALM011E/HORM011;lsalhor02=SALM021E/HORM021;lsalhor03=SALM031E/HORM031;
lsalhor04=SALM041E/HORM041;lsalhor05=SALM051E/HORM051;lsalhor06=SALM061E/HORM061;
lsalhor07=SALM071E/HORM071;lsalhor08=SALM081E/HORM081;lsalhor09=SALM091E/HORM091;
lsalhor10=SALM101E/HORM101;lsalhor11=SALM111E/HORM111;lsalhor12=SALM121E/HORM121;
lindichor01=0;lindichor02=0;lindichor03=0;lindichor04=0;lindichor05=0;lindichor06=0;
lindichor07=0;lindichor08=0;lindichor09=0;lindichor10=0;lindichor11=0;lindichor12=0;
run;

%macro creaind(nom1,nom2);
select;when (&nom1 = 0 or &nom1 = .) &nom2=1 ;otherwise;end;
%MEND creaind;

data ecriture.ACEMO_salhor;set ecriture.ACEMO_salhor;
%creaind(salhor01,indichor01);%creaind(salhor02,indichor02);%creaind(salhor03,indichor03);
%creaind(salhor04,indichor04);%creaind(salhor05,indichor05);%creaind(salhor06,indichor06);
%creaind(salhor07,indichor07);%creaind(salhor08,indichor08);%creaind(salhor09,indichor09);
%creaind(salhor10,indichor10);%creaind(salhor11,indichor11);%creaind(salhor12,indichor12);
%creaind(lsalhor01,lindichor01);%creaind(lsalhor02,lindichor02);%creaind(lsalhor03,lindichor03);
%creaind(lsalhor04,lindichor04);%creaind(lsalhor05,lindichor05);%creaind(lsalhor06,lindichor06);
%creaind(lsalhor07,lindichor07);%creaind(lsalhor08,lindichor08);%creaind(lsalhor09,lindichor09);
%creaind(lsalhor10,lindichor10);%creaind(lsalhor11,lindichor11);%creaind(lsalhor12,lindichor12);
run;

/******************************************************/
/* ON CALCULE LE LN ET DLN DU SALAIRE HORAIRE         */ 
/* POUR LES 12 CATEGORIES                             */
/******************************************************/
data ecriture.ACEMO_salhor;set ecriture.ACEMO_salhor;
lnsalhor01=log(salhor01);lnsalhor02=log(salhor02);lnsalhor03=log(salhor03);
lnsalhor04=log(salhor04);lnsalhor05=log(salhor05);lnsalhor06=log(salhor06);
lnsalhor07=log(salhor07);lnsalhor08=log(salhor08);lnsalhor09=log(salhor09);
lnsalhor10=log(salhor10);lnsalhor11=log(salhor11);lnsalhor12=log(salhor12);
dlnsalhor01=log(salhor01/lsalhor01);
dlnsalhor02=log(salhor02/lsalhor02);
dlnsalhor03=log(salhor03/lsalhor03);
dlnsalhor04=log(salhor04/lsalhor04);
dlnsalhor05=log(salhor05/lsalhor05);
dlnsalhor06=log(salhor06/lsalhor06);
dlnsalhor07=log(salhor07/lsalhor07);
dlnsalhor08=log(salhor08/lsalhor08);
dlnsalhor09=log(salhor09/lsalhor09);
dlnsalhor10=log(salhor10/lsalhor10);
dlnsalhor11=log(salhor11/lsalhor11);
dlnsalhor12=log(salhor12/lsalhor12);
run;

/******************************************************/
/* ON CALCULE Q1, Q3 ET MEDIANE DE                    */
/* LNSALHORxx                                         */
/******************************************************/
proc univariate data=ecriture.ACEMO_salhor noprint;
var 
lnsalhor01 lnsalhor02 lnsalhor03 lnsalhor04 lnsalhor05 lnsalhor06
lnsalhor07 lnsalhor08 lnsalhor09 lnsalhor10 lnsalhor11 lnsalhor12 
;output out = resu_ln_salhor 
q1=  q1ln01 q1ln02 q1ln03 q1ln04 q1ln05 q1ln06 
     q1ln07 q1ln08 q1ln09 q1ln10 q1ln11 q1ln12 
q3=  q3ln01 q3ln02 q3ln03 q3ln04 q3ln05 q3ln06 
     q3ln07 q3ln08 q3ln09 q3ln10 q3ln11 q3ln12 
median=mln01 mln02 mln03 mln04 mln05 mln06 
       mln07 mln08 mln09 mln10 mln11 mln12 
;run;
proc print data=resu_ln_salhor;run; 

/******************************************************/
/* ON CALCULE Q1, Q3 ET MEDIANE DE                    */
/* DLNSALHORxx                                        */
/******************************************************/
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor01 ne 0 )) noprint;
var dlnsalhor01;output out = resu_dln01_salhor q1=  q1dln01 q3=  q3dln01 median=mdln01;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor02 ne 0 )) noprint;
var dlnsalhor02;output out = resu_dln02_salhor q1=  q1dln02 q3=  q3dln02 median=mdln02;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor03 ne 0 )) noprint;
var dlnsalhor03;output out = resu_dln03_salhor q1=  q1dln03 q3=  q3dln03 median=mdln03;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor04 ne 0 )) noprint;
var dlnsalhor04;output out = resu_dln04_salhor q1=  q1dln04 q3=  q3dln04 median=mdln04;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor05 ne 0 )) noprint;
var dlnsalhor05;output out = resu_dln05_salhor q1=  q1dln05 q3=  q3dln05 median=mdln05;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor06 ne 0 )) noprint;
var dlnsalhor06;output out = resu_dln06_salhor q1=  q1dln06 q3=  q3dln06 median=mdln06;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor07 ne 0 )) noprint;
var dlnsalhor07;output out = resu_dln07_salhor q1=  q1dln07 q3=  q3dln07 median=mdln07;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor08 ne 0 )) noprint;
var dlnsalhor08;output out = resu_dln08_salhor q1=  q1dln08 q3=  q3dln08 median=mdln08;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor09 ne 0 )) noprint;
var dlnsalhor09;output out = resu_dln09_salhor q1=  q1dln09 q3=  q3dln09 median=mdln09;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor10 ne 0 )) noprint;
var dlnsalhor10;output out = resu_dln10_salhor q1=  q1dln10 q3=  q3dln10 median=mdln10;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor11 ne 0 )) noprint;
var dlnsalhor11;output out = resu_dln11_salhor q1=  q1dln11 q3=  q3dln11 median=mdln11;
proc univariate data=ecriture.ACEMO_salhor(where=(dlnsalhor12 ne 0 )) noprint;
var dlnsalhor12;output out = resu_dln12_salhor q1=  q1dln12 q3=  q3dln12 median=mdln12;
run;
data ecriture.resu_dln_salhor;
merge resu_ln_salhor resu_dln01_salhor resu_dln02_salhor resu_dln03_salhor resu_dln04_salhor
resu_dln05_salhor resu_dln06_salhor resu_dln07_salhor resu_dln08_salhor resu_dln09_salhor 
resu_dln10_salhor resu_dln11_salhor resu_dln12_salhor;run;
 
/******************************************************/
/* INTEGRATION DES Q1, Q3 ET MEDIANE DE               */
/* LNSALHORxx et DLNSALHORxx                          */
/* DANS LE FICHIER COMPLET                            */ 
/******************************************************/
data ecriture.ACEMO_salhor ;set ecriture.ACEMO_salhor;bidon=1;run;
data ecriture.resu_dln_salhor;set ecriture.resu_dln_salhor;bidon=1;run;
data ecriture.ACEMO_salhor_dln;merge ecriture.ACEMO_salhor ecriture.resu_dln_salhor;
by bidon;run; 

/**********************************************************/
/* cr�ation d'une indicatrice indicaberhorxx valant :     */
/*   - 0 si pas valeur extr�me de lnsalhorxx dlnsalhorxx  */ 
/*   - 1 si  salhor** = 0 ou . cad si indichorxx=1        */
/*   - 2 si valeur extr�me de lnsalhorxx                  */
/*   - 3 si valeur extr�me de dlnsalhorxx                 */
/**********************************************************/
%macro aber(nom1,nom2,nom3,nom4,nom5,nom6,nom7,nom8,nom9,nom10);
format &nom1 best12.;
&nom1=0; 
if &nom2 = 1 then &nom1=1;
if &nom2 = 0 and (abs(&nom3-&nom4) ge 5*(&nom5-&nom6))  then &nom1=2;
if &nom2 = 0 and (abs(&nom7-&nom8) ge 5*(&nom9-&nom10)) then &nom1=3;
%MEND aber ;

data ecriture.ACEMO_salhor_indi; set ecriture.ACEMO_salhor_dln;
%aber(indicaberhor01,indichor01,lnsalhor01,mln01,q3ln01,q1ln01,dlnsalhor01,mdln01,q3dln01,q1dln01);
%aber(indicaberhor02,indichor02,lnsalhor02,mln02,q3ln02,q1ln02,dlnsalhor02,mdln02,q3dln02,q1dln02);
%aber(indicaberhor03,indichor03,lnsalhor03,mln03,q3ln03,q1ln03,dlnsalhor03,mdln03,q3dln03,q1dln03);
%aber(indicaberhor04,indichor04,lnsalhor04,mln04,q3ln04,q1ln04,dlnsalhor04,mdln04,q3dln04,q1dln04);
%aber(indicaberhor05,indichor05,lnsalhor05,mln05,q3ln05,q1ln05,dlnsalhor05,mdln05,q3dln05,q1dln05);
%aber(indicaberhor06,indichor06,lnsalhor06,mln06,q3ln06,q1ln06,dlnsalhor06,mdln06,q3dln06,q1dln06);
%aber(indicaberhor07,indichor07,lnsalhor07,mln07,q3ln07,q1ln07,dlnsalhor07,mdln07,q3dln07,q1dln07);
%aber(indicaberhor08,indichor08,lnsalhor08,mln08,q3ln08,q1ln08,dlnsalhor08,mdln08,q3dln08,q1dln08);
%aber(indicaberhor09,indichor09,lnsalhor09,mln09,q3ln09,q1ln09,dlnsalhor09,mdln09,q3dln09,q1dln09);
%aber(indicaberhor10,indichor10,lnsalhor10,mln10,q3ln10,q1ln10,dlnsalhor10,mdln10,q3dln10,q1dln10);
%aber(indicaberhor11,indichor11,lnsalhor11,mln11,q3ln11,q1ln11,dlnsalhor11,mdln11,q3dln11,q1dln11);
%aber(indicaberhor12,indichor12,lnsalhor12,mln12,q3ln12,q1ln12,dlnsalhor12,mdln12,q3dln12,q1dln12);
run;

proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor01*indichor01;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor02*indichor02;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor03*indichor03;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor04*indichor04;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor05*indichor05;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor06*indichor06;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor07*indichor07;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor08*indichor08;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor09*indichor09;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor10*indichor10;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor11*indichor11;run;
proc freq data= ecriture.ACEMO_salhor_indi;table indicaberhor12*indichor12;run;

/******************************************************/
/* proc univariate avec et sans valeurs extr�mes      */
/******************************************************/
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor01 ne 0 )) ;
var dlnsalhor01 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor01 ne 0 and indicaberhor01=0));
var dlnsalhor01;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor02 ne 0 )) ;
var dlnsalhor02 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor02 ne 0 and indicaberhor02=0));
var dlnsalhor02;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor03 ne 0 )) ;
var dlnsalhor03 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor03 ne 0 and indicaberhor03=0));
var dlnsalhor03;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor04 ne 0 )) ;
var dlnsalhor04 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor04 ne 0 and indicaberhor04=0));
var dlnsalhor04;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor05 ne 0 )) ;
var dlnsalhor05 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor05 ne 0 and indicaberhor05=0));
var dlnsalhor05;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor06 ne 0 )) ;
var dlnsalhor06 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor06 ne 0 and indicaberhor06=0));
var dlnsalhor06;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor07 ne 0 )) ;
var dlnsalhor07 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor07 ne 0 and indicaberhor07=0));
var dlnsalhor07;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor08 ne 0 )) ;
var dlnsalhor08 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor08 ne 0 and indicaberhor08=0));
var dlnsalhor08;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor09 ne 0 )) ;
var dlnsalhor09 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor09 ne 0 and indicaberhor09=0));
var dlnsalhor09;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor10 ne 0 )) ;
var dlnsalhor10 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor10 ne 0 and indicaberhor10=0));
var dlnsalhor10;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor11 ne 0 )) ;
var dlnsalhor11 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor11 ne 0 and indicaberhor11=0));
var dlnsalhor11;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor12 ne 0 )) ;
var dlnsalhor12 ;run;
proc univariate data=ecriture.ACEMO_salhor_indi(where=(dlnsalhor12 ne 0 and indicaberhor12=0));
var dlnsalhor12;run;

/******************************************************/
/* calcul des fr�quences de changement de salaire     */
/* indic_chgt_salhorxx                                   */
/* indic_chgt_salhorxx_posi                              */
/* indic_chgt_salhorxx_nega                              */
/******************************************************/
proc sort data=ecriture.ACEMO_salhor_indi out=ecriture.ACEMO_salhor_indi_tri;by siret date;
run;

/* macro */
%macro chgt(nom1,nom2,nom3,nom4);
select;when(&nom1 = 0) &nom2=0;when(&nom1 = .) &nom2=.;otherwise &nom2=1;end;
select;when(&nom1 gt 0) &nom3=1;otherwise &nom3=0;end;
select;when(&nom1 = .) &nom3=.;otherwise;end;
select;when(&nom1 lt 0) &nom4=1;otherwise &nom4=0;end;
select;when(&nom1 = .) &nom4=.;otherwise;end;
%MEND chgt;

data ecriture.ACEMO_salhor_indi_chgt;set ecriture.ACEMO_salhor_indi_tri;
%chgt(dlnsalhor01,indic_chgt_salhor01,indic_chgt_salhor01_posi,indic_chgt_salhor01_nega)
%chgt(dlnsalhor02,indic_chgt_salhor02,indic_chgt_salhor02_posi,indic_chgt_salhor02_nega)
%chgt(dlnsalhor03,indic_chgt_salhor03,indic_chgt_salhor03_posi,indic_chgt_salhor03_nega)
%chgt(dlnsalhor04,indic_chgt_salhor04,indic_chgt_salhor04_posi,indic_chgt_salhor04_nega)
%chgt(dlnsalhor05,indic_chgt_salhor05,indic_chgt_salhor05_posi,indic_chgt_salhor05_nega)
%chgt(dlnsalhor06,indic_chgt_salhor06,indic_chgt_salhor06_posi,indic_chgt_salhor06_nega)
%chgt(dlnsalhor07,indic_chgt_salhor07,indic_chgt_salhor07_posi,indic_chgt_salhor07_nega)
%chgt(dlnsalhor08,indic_chgt_salhor08,indic_chgt_salhor08_posi,indic_chgt_salhor08_nega)
%chgt(dlnsalhor09,indic_chgt_salhor09,indic_chgt_salhor09_posi,indic_chgt_salhor09_nega)
%chgt(dlnsalhor10,indic_chgt_salhor10,indic_chgt_salhor10_posi,indic_chgt_salhor10_nega)
%chgt(dlnsalhor11,indic_chgt_salhor11,indic_chgt_salhor11_posi,indic_chgt_salhor11_nega)
%chgt(dlnsalhor12,indic_chgt_salhor12,indic_chgt_salhor12_posi,indic_chgt_salhor12_nega)
run;

proc sort data=ecriture.ACEMO_salhor_indi_chgt;by date;run;

proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor01/ noprint out=ecriture.ichgtsalhor01 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor02/ noprint out=ecriture.ichgtsalhor02 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor03/ noprint out=ecriture.ichgtsalhor03 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor04/ noprint out=ecriture.ichgtsalhor04 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor05/ noprint out=ecriture.ichgtsalhor05 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor06/ noprint out=ecriture.ichgtsalhor06 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor07/ noprint out=ecriture.ichgtsalhor07 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor08/ noprint out=ecriture.ichgtsalhor08 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor09/ noprint out=ecriture.ichgtsalhor09 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor10/ noprint out=ecriture.ichgtsalhor10 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor11/ noprint out=ecriture.ichgtsalhor11 ;by date;run;
proc freq data=ecriture.ACEMO_salhor_indi_chgt;table indic_chgt_salhor12/ noprint out=ecriture.ichgtsalhor12 ;by date;run;



proc contents data=ecriture.ACEMO_salhor_indi_chgt;run;

proc sort data=ecriture.ACEMO_salhor_indi_chgt ;by siret date;run;



/* ATTENTION : VOIR VARIABLES A SUPPRIMER !!!!!!!!!!!!!!     */
data ecriture.ACEMO_salhor_indi_chgt;set ecriture.ACEMO_salhor_indi_chgt;  
drop
bidon
mdln01 mdln02 mdln03 mdln04 mdln05 mdln06 mdln07
mdln08 mdln09 mdln10 mdln11 mdln12 mln01 mln02 mln03 mln04 mln05 mln06 mln07 mln08 mln09 mln10 mln11
mln12 q1dln01 q1dln02 q1dln03 q1dln04 q1dln05 q1dln06 q1dln07 q1dln08 q1dln09 q1dln10 q1dln11
q1dln12 q1ln01 q1ln02 q1ln03 q1ln04 q1ln05 q1ln06 q1ln07 q1ln08 q1ln09 q1ln10 q1ln11 q1ln12 q3dln01
q3dln02 q3dln03 q3dln04 q3dln05 q3dln06 q3dln07 q3dln08 q3dln09 q3dln10 q3dln11 q3dln12 q3ln01
q3ln02 q3ln03 q3ln04 q3ln05 q3ln06 q3ln07 q3ln08 q3ln09 q3ln10 q3ln11 q3ln12;
run;

/**************************************************************/
/* FIN DE CREATION DES INDICATRICES SUR LES SALAIRES HORAIRES */
/**************************************************************/



/**************************************************************************************/
/**********************         V - SALAIRE MENSUEL          *************************/
/**************************************************************************************/ 


/******************************************************/
/* LE LAG DES SALAIRES EST DEJA CALCULE               */
/* ON SUPPOSE QUE LE LAG N'EXISTE QUE POUR UN MEME    */
/* SIRET A DES DATES QUI SE SUIVENT                   */
/* APRES VERIF. CELA SEMBLE ETRE LE CAS...            */               
/* ATTENTION AUX VALEURS EXTREMES DES VARIABLES !     */ 
/* LES VALEURS DE SALMENSXX EGALES A 0 OU .           */
/* SONT REPEREES PAR INDICxx=1                        */
/* LES VALEURS DE LSALMENSXX EGALES A 0 OU .          */
/* SONT REPEREES PAR LINDICxx=1                       */
/******************************************************/
/* tri par SIRET DATE */
/*proc sort data=lecture.ACEMO_1999_2006_apure3; by SIRET DATE; run;*/

data ecriture.ACEMO_salmens;set ecriture.ACEMO_salhor_indi_chgt;
indicmens01=0;indicmens02=0;indicmens03=0;indicmens04=0;indicmens05=0;indicmens06=0;
indicmens07=0;indicmens08=0;indicmens09=0;indicmens10=0;indicmens11=0;indicmens12=0;
lindicmens01=0;lindicmens02=0;lindicmens03=0;lindicmens04=0;lindicmens05=0;lindicmens06=0;
lindicmens07=0;lindicmens08=0;lindicmens09=0;lindicmens10=0;lindicmens11=0;lindicmens12=0;
run;

%macro creaind(nom1,nom2);
select;when (&nom1 = 0 or &nom1 = .) &nom2=1 ;otherwise;end;
%MEND creaind;

data ecriture.ACEMO_salmens;set ecriture.ACEMO_salmens;
%creaind(SALM01E,indicmens01);%creaind(SALM02E,indicmens02);%creaind(SALM03E,indicmens03);
%creaind(SALM04E,indicmens04);%creaind(SALM05E,indicmens05);%creaind(SALM06E,indicmens06);
%creaind(SALM07E,indicmens07);%creaind(SALM08E,indicmens08);%creaind(SALM09E,indicmens09);
%creaind(SALM10E,indicmens10);%creaind(SALM11E,indicmens11);%creaind(SALM12E,indicmens12);
%creaind(SALM011E,lindicmens01);%creaind(SALM021E,lindicmens02);%creaind(SALM031E,lindicmens03);
%creaind(SALM041E,lindicmens04);%creaind(SALM051E,lindicmens05);%creaind(SALM061E,lindicmens06);
%creaind(SALM071E,lindicmens07);%creaind(SALM081E,lindicmens08);%creaind(SALM091E,lindicmens09);
%creaind(SALM101E,lindicmens10);%creaind(SALM111E,lindicmens11);%creaind(SALM121E,lindicmens12);
run;

/******************************************************/
/* ON CALCULE LE LN ET DLN DU SALAIRE MESUEL          */ 
/* POUR LES 12 CATEGORIES                             */
/******************************************************/
data ecriture.ACEMO_salmens;set ecriture.ACEMO_salmens;
lnsalmens01=log(SALM01E);
lnsalmens02=log(SALM02E);
lnsalmens03=log(SALM03E);
lnsalmens04=log(SALM04E);
lnsalmens05=log(SALM05E);
lnsalmens06=log(SALM06E);
lnsalmens07=log(SALM07E);
lnsalmens08=log(SALM08E);
lnsalmens09=log(SALM09E);
lnsalmens10=log(SALM10E);
lnsalmens11=log(SALM11E);
lnsalmens12=log(SALM12E);
dlnsalmens01=log(SALM01E/SALM011E);
dlnsalmens02=log(SALM02E/SALM021E);
dlnsalmens03=log(SALM03E/SALM031E);
dlnsalmens04=log(SALM04E/SALM041E);
dlnsalmens05=log(SALM05E/SALM051E);
dlnsalmens06=log(SALM06E/SALM061E);
dlnsalmens07=log(SALM07E/SALM071E);
dlnsalmens08=log(SALM08E/SALM081E);
dlnsalmens09=log(SALM09E/SALM091E);
dlnsalmens10=log(SALM10E/SALM101E);
dlnsalmens11=log(SALM11E/SALM111E);
dlnsalmens12=log(SALM12E/SALM121E);
run;

/******************************************************/
/* ON CALCULE Q1, Q3 ET MEDIANE DE                    */
/* LNSALMENSxx                                        */
/******************************************************/
proc univariate data=ecriture.ACEMO_salmens noprint;
var 
lnsalmens01 lnsalmens02 lnsalmens03 lnsalmens04 lnsalmens05 lnsalmens06
lnsalmens07 lnsalmens08 lnsalmens09 lnsalmens10 lnsalmens11 lnsalmens12 
;output out = resu_ln_salmens 
q1=  q1ln01 q1ln02 q1ln03 q1ln04 q1ln05 q1ln06 
     q1ln07 q1ln08 q1ln09 q1ln10 q1ln11 q1ln12 
q3=  q3ln01 q3ln02 q3ln03 q3ln04 q3ln05 q3ln06 
     q3ln07 q3ln08 q3ln09 q3ln10 q3ln11 q3ln12 
median=mln01 mln02 mln03 mln04 mln05 mln06 
       mln07 mln08 mln09 mln10 mln11 mln12 
;run;
proc print data=resu_ln_salmens;run; 

/******************************************************/
/* ON CALCULE Q1, Q3 ET MEDIANE DE                    */
/* DLNSALMENSxx                                       */
/******************************************************/
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens01 ne 0 )) noprint;
var dlnsalmens01;output out = resu_dln01_salmens q1=  q1dln01 q3=  q3dln01 median=mdln01;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens02 ne 0 )) noprint;
var dlnsalmens02;output out = resu_dln02_salmens q1=  q1dln02 q3=  q3dln02 median=mdln02;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens03 ne 0 )) noprint;
var dlnsalmens03;output out = resu_dln03_salmens q1=  q1dln03 q3=  q3dln03 median=mdln03;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens04 ne 0 )) noprint;
var dlnsalmens04;output out = resu_dln04_salmens q1=  q1dln04 q3=  q3dln04 median=mdln04;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens05 ne 0 )) noprint;
var dlnsalmens05;output out = resu_dln05_salmens q1=  q1dln05 q3=  q3dln05 median=mdln05;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens06 ne 0 )) noprint;
var dlnsalmens06;output out = resu_dln06_salmens q1=  q1dln06 q3=  q3dln06 median=mdln06;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens07 ne 0 )) noprint;
var dlnsalmens07;output out = resu_dln07_salmens q1=  q1dln07 q3=  q3dln07 median=mdln07;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens08 ne 0 )) noprint;
var dlnsalmens08;output out = resu_dln08_salmens q1=  q1dln08 q3=  q3dln08 median=mdln08;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens09 ne 0 )) noprint;
var dlnsalmens09;output out = resu_dln09_salmens q1=  q1dln09 q3=  q3dln09 median=mdln09;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens10 ne 0 )) noprint;
var dlnsalmens10;output out = resu_dln10_salmens q1=  q1dln10 q3=  q3dln10 median=mdln10;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens11 ne 0 )) noprint;
var dlnsalmens11;output out = resu_dln11_salmens q1=  q1dln11 q3=  q3dln11 median=mdln11;
proc univariate data=ecriture.ACEMO_salmens(where=(dlnsalmens12 ne 0 )) noprint;
var dlnsalmens12;output out = resu_dln12_salmens q1=  q1dln12 q3=  q3dln12 median=mdln12;
run;
data ecriture.resu_dln_salmens; 
merge resu_ln_salmens resu_dln01_salmens resu_dln02_salmens resu_dln03_salmens resu_dln04_salmens
resu_dln05_salmens resu_dln06_salmens resu_dln07_salmens resu_dln08_salmens resu_dln09_salmens
resu_dln10_salmens resu_dln11_salmens resu_dln12_salmens;run;
 
/******************************************************/
/* INTEGRATION DES Q1, Q3 ET MEDIANE DE               */
/* LNSALMENSxx et DLNSALMENSxx                        */
/* DANS LE FICHIER COMPLET                            */ 
/******************************************************/
data ecriture.ACEMO_salmens;set ecriture.ACEMO_salmens;bidon=1;run;
data ecriture.resu_dln_salmens;set ecriture.resu_dln_salmens;bidon=1;run;
data ecriture.ACEMO_salmens_dln;merge ecriture.ACEMO_salmens ecriture.resu_dln_salmens;
by bidon;run; 

/************************************************************/
/* cr�ation d'une indicatrice indicabermensxx valant :      */
/*   - 0 si pas valeur extr�me de lnsalmensxx dlnsalmensxx  */ 
/*   - 1 si indicmensxx = 0 ou .                            */
/*   - 2 si valeur extr�me de lnsalmensxx                   */
/*   - 3 si valeur extr�me de dlnsalmensxx                  */
/************************************************************/
%macro aber(nom1,nom2,nom3,nom4,nom5,nom6,nom7,nom8,nom9,nom10);
format &nom1 best12.;
&nom1=0; 
if &nom2 = 1 then &nom1=1;
if &nom2 = 0 and (abs(&nom3-&nom4) ge 5*(&nom5-&nom6))  then &nom1=2;
if &nom2 = 0 and (abs(&nom7-&nom8) ge 5*(&nom9-&nom10)) then &nom1=3;
%MEND aber ;

data ecriture.ACEMO_salmens_indi; set ecriture.ACEMO_salmens_dln;
%aber(indicabermens01,indicmens01,lnsalmens01,mln01,q3ln01,q1ln01,dlnsalmens01,mdln01,q3dln01,q1dln01);
%aber(indicabermens02,indicmens02,lnsalmens02,mln02,q3ln02,q1ln02,dlnsalmens02,mdln02,q3dln02,q1dln02);
%aber(indicabermens03,indicmens03,lnsalmens03,mln03,q3ln03,q1ln03,dlnsalmens03,mdln03,q3dln03,q1dln03);
%aber(indicabermens04,indicmens04,lnsalmens04,mln04,q3ln04,q1ln04,dlnsalmens04,mdln04,q3dln04,q1dln04);
%aber(indicabermens05,indicmens05,lnsalmens05,mln05,q3ln05,q1ln05,dlnsalmens05,mdln05,q3dln05,q1dln05);
%aber(indicabermens06,indicmens06,lnsalmens06,mln06,q3ln06,q1ln06,dlnsalmens06,mdln06,q3dln06,q1dln06);
%aber(indicabermens07,indicmens07,lnsalmens07,mln07,q3ln07,q1ln07,dlnsalmens07,mdln07,q3dln07,q1dln07);
%aber(indicabermens08,indicmens08,lnsalmens08,mln08,q3ln08,q1ln08,dlnsalmens08,mdln08,q3dln08,q1dln08);
%aber(indicabermens09,indicmens09,lnsalmens09,mln09,q3ln09,q1ln09,dlnsalmens09,mdln09,q3dln09,q1dln09);
%aber(indicabermens10,indicmens10,lnsalmens10,mln10,q3ln10,q1ln10,dlnsalmens10,mdln10,q3dln10,q1dln10);
%aber(indicabermens11,indicmens11,lnsalmens11,mln11,q3ln11,q1ln11,dlnsalmens11,mdln11,q3dln11,q1dln11);
%aber(indicabermens12,indicmens12,lnsalmens12,mln12,q3ln12,q1ln12,dlnsalmens12,mdln12,q3dln12,q1dln12);
run;

proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens01*indicmens01;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens02*indicmens02;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens03*indicmens03;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens04*indicmens04;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens05*indicmens05;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens06*indicmens06;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens07*indicmens07;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens08*indicmens08;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens09*indicmens09;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens10*indicmens10;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens11*indicmens11;run;
proc freq data= ecriture.ACEMO_salmens_indi;table indicabermens12*indicmens12;run;

/******************************************************/
/* proc univariate avec et sans valeurs extr�mes      */
/******************************************************/
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens01 ne 0 )) ;
var dlnsalmens01 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens01 ne 0 and indicabermens01=0));
var dlnsalmens01;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens02 ne 0 )) ;
var dlnsalmens02 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens02 ne 0 and indicabermens02=0));
var dlnsalmens02;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens03 ne 0 )) ;
var dlnsalmens03 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens03 ne 0 and indicabermens03=0));
var dlnsalmens03;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens04 ne 0 )) ;
var dlnsalmens04 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens04 ne 0 and indicabermens04=0));
var dlnsalmens04;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens05 ne 0 )) ;
var dlnsalmens05 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens05 ne 0 and indicabermens05=0));
var dlnsalmens05;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens06 ne 0 )) ;
var dlnsalmens06 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens06 ne 0 and indicabermens06=0));
var dlnsalmens06;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens07 ne 0 )) ;
var dlnsalmens07 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens07 ne 0 and indicabermens07=0));
var dlnsalmens07;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens08 ne 0 )) ;
var dlnsalmens08 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens08 ne 0 and indicabermens08=0));
var dlnsalmens08;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens09 ne 0 )) ;
var dlnsalmens09 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens09 ne 0 and indicabermens09=0));
var dlnsalmens09;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens10 ne 0 )) ;
var dlnsalmens10 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens10 ne 0 and indicabermens10=0));
var dlnsalmens10;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens11 ne 0 )) ;
var dlnsalmens11 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens11 ne 0 and indicabermens11=0));
var dlnsalmens11;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens12 ne 0 )) ;
var dlnsalmens12 ;run;
proc univariate data=ecriture.ACEMO_salmens_indi(where=(dlnsalmens12 ne 0 and indicabermens12=0));
var dlnsalmens12;run;

/******************************************************/
/* calcul des fr�quences de changement de salaire     */
/* indic_chgt_salxx                                   */
/* indic_chgt_salxx_posi                              */
/* indic_chgt_salxx_nega                              */
/******************************************************/
proc sort data=ecriture.ACEMO_salmens_indi out=ecriture.ACEMO_salmens_indi_tri;by siret date;
run;

/* macro */
%macro chgt(nom1,nom2,nom3,nom4);
select;when(&nom1 = 0) &nom2=0;when(&nom1 = .) &nom2=.;otherwise &nom2=1;end;
select;when(&nom1 gt 0) &nom3=1;otherwise &nom3=0;end;
select;when(&nom1 = .) &nom3=.;otherwise;end;
select;when(&nom1 lt 0) &nom4=1;otherwise &nom4=0;end;
select;when(&nom1 = .) &nom4=.;otherwise;end;
%MEND chgt;

data ecriture.ACEMO_salmens_indi_chgt;set ecriture.ACEMO_salmens_indi_tri;
%chgt(dlnsalmens01,indic_chgt_salmens01,indic_chgt_salmens01_posi,indic_chgt_salmens01_nega)
%chgt(dlnsalmens02,indic_chgt_salmens02,indic_chgt_salmens02_posi,indic_chgt_salmens02_nega)
%chgt(dlnsalmens03,indic_chgt_salmens03,indic_chgt_salmens03_posi,indic_chgt_salmens03_nega)
%chgt(dlnsalmens04,indic_chgt_salmens04,indic_chgt_salmens04_posi,indic_chgt_salmens04_nega)
%chgt(dlnsalmens05,indic_chgt_salmens05,indic_chgt_salmens05_posi,indic_chgt_salmens05_nega)
%chgt(dlnsalmens06,indic_chgt_salmens06,indic_chgt_salmens06_posi,indic_chgt_salmens06_nega)
%chgt(dlnsalmens07,indic_chgt_salmens07,indic_chgt_salmens07_posi,indic_chgt_salmens07_nega)
%chgt(dlnsalmens08,indic_chgt_salmens08,indic_chgt_salmens08_posi,indic_chgt_salmens08_nega)
%chgt(dlnsalmens09,indic_chgt_salmens09,indic_chgt_salmens09_posi,indic_chgt_salmens09_nega)
%chgt(dlnsalmens10,indic_chgt_salmens10,indic_chgt_salmens10_posi,indic_chgt_salmens10_nega)
%chgt(dlnsalmens11,indic_chgt_salmens11,indic_chgt_salmens11_posi,indic_chgt_salmens11_nega)
%chgt(dlnsalmens12,indic_chgt_salmens12,indic_chgt_salmens12_posi,indic_chgt_salmens12_nega)
run;

proc sort data=ecriture.ACEMO_salmens_indi_chgt;by date;run;

proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens01/ noprint out=ecriture.ichgtsal01 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens02/ noprint out=ecriture.ichgtsal02 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens03/ noprint out=ecriture.ichgtsal03 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens04/ noprint out=ecriture.ichgtsal04 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens05/ noprint out=ecriture.ichgtsal05 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens06/ noprint out=ecriture.ichgtsal06 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens07/ noprint out=ecriture.ichgtsal07 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens08/ noprint out=ecriture.ichgtsal08 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens09/ noprint out=ecriture.ichgtsal09 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens10/ noprint out=ecriture.ichgtsal10 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens11/ noprint out=ecriture.ichgtsal11 ;by date;run;
proc freq data=ecriture.ACEMO_salmens_indi_chgt;table indic_chgt_salmens12/ noprint out=ecriture.ichgtsal12 ;by date;run;

proc sort data=ecriture.ACEMO_salmens_indi_chgt;by siret date;run;





/************************************************************************************/
/***************         VI - TRANSPOSITION DE LA BASE           ********************/
/************************************************************************************/

data ecriture.ACEMO_SALHOR_SALMENS; set ecriture.ACEMO_salmens_indi_chgt;run;
proc contents data=ecriture.ACEMO_SALHOR_SALMENS;run;

/************************************/
/*  ON CREE UNE BASE PAR CATEGORIE  */
/************************************/
/* CAT01 */
data ecriture.cat01;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR PREST1
R_RETOUR NUMERO
HORM01 HORM011 SALM01 SALM01E SALM011 SALM011E 
salhor01 lsalhor01 lnsalhor01 dlnsalhor01 indichor01 lindichor01 indicaberhor01
indic_chgt_salhor01 indic_chgt_salhor01_nega indic_chgt_salhor01_posi 
lnsalmens01 dlnsalmens01
indic_chgt_salmens01 indic_chgt_salmens01_nega indic_chgt_salmens01_posi    
indicmens01 lindicmens01 indicabermens01
ISALM01 ISALMOUV ISALMTOT POUV PTOT pcatEntSect01  ;
run;
data ecriture.cat01;set ecriture.cat01;
rename	SALM01 = SALMENS;
rename	SALM011 = LSALMENS;
rename	HORM01 = HORMENS;
rename	HORM011 = LHORMENS;
rename	SALM011E = LSALMENSE;
rename	SALM01E = SALMENSE;
rename	salhor01 = SALHOR;
rename	lsalhor01 = LSALHOR;
rename	lnsalhor01 = LNSALHOR;
rename	dlnsalhor01 = DLNSALHOR;
rename	indic_chgt_salhor01 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor01_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor01_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor01 = INDICABERHOR;
rename	indichor01 = INDICHOR;
rename	lindichor01 = LINDICHOR;
rename	lnsalmens01 = LNSALMENSE;
rename	dlnsalmens01 = DLNSALMENSE;
rename	indicmens01 = INDICMENS	;
rename	lindicmens01 = LINDICMENS;
rename	indic_chgt_salmens01 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens01_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens01_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens01 = INDICABERMENS	;
rename  ISALM01 = ISALM;
rename  pcatEntSect01 = PCATENTSECT;

CAT='cat01';
run;

/* CAT02 */
data ecriture.cat02;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR PREST1
R_RETOUR NUMERO
HORM02 HORM021 SALM02 SALM02E SALM021 SALM021E 
salhor02 lsalhor02 lnsalhor02 dlnsalhor02 indichor02 lindichor02 indicaberhor02
indic_chgt_salhor02 indic_chgt_salhor02_nega indic_chgt_salhor02_posi 
lnsalmens02 dlnsalmens02
indic_chgt_salmens02 indic_chgt_salmens02_nega indic_chgt_salmens02_posi    
indicmens02 lindicmens02 indicabermens02
ISALM02 ISALMOUV ISALMTOT POUV PTOT pcatEntSect02  ;
run;
data ecriture.cat02;set ecriture.cat02;
rename	SALM02 = SALMENS;
rename	SALM021 = LSALMENS;
rename	HORM02 = HORMENS;
rename	HORM021 = LHORMENS;
rename	SALM021E = LSALMENSE;
rename	SALM02E = SALMENSE;
rename	salhor02 = SALHOR;
rename	lsalhor02 = LSALHOR;
rename	lnsalhor02 = LNSALHOR;
rename	dlnsalhor02 = DLNSALHOR;
rename	indic_chgt_salhor02 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor02_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor02_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor02 = INDICABERHOR;
rename	indichor02 = INDICHOR;
rename	lindichor02 = LINDICHOR;
rename	lnsalmens02 = LNSALMENSE;
rename	dlnsalmens02 = DLNSALMENSE;
rename	indicmens02 = INDICMENS	;
rename	lindicmens02 = LINDICMENS;
rename	indic_chgt_salmens02 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens02_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens02_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens02 = INDICABERMENS	;
rename  ISALM02 = ISALM;
rename  pcatEntSect02 = PCATENTSECT;

CAT='cat02';
run;

/* CAT03 */
data ecriture.cat03;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR PREST1
R_RETOUR NUMERO
HORM03 HORM031 SALM03 SALM03E SALM031 SALM031E 
salhor03 lsalhor03 lnsalhor03 dlnsalhor03 indichor03 lindichor03 indicaberhor03
indic_chgt_salhor03 indic_chgt_salhor03_nega indic_chgt_salhor03_posi 
lnsalmens03 dlnsalmens03
indic_chgt_salmens03 indic_chgt_salmens03_nega indic_chgt_salmens03_posi    
indicmens03 lindicmens03 indicabermens03
ISALM03 ISALMOUV ISALMTOT POUV PTOT pcatEntSect03 ;
run;
data ecriture.cat03;set ecriture.cat03;
rename	SALM03 = SALMENS;
rename	SALM031 = LSALMENS;
rename	HORM03 = HORMENS;
rename	HORM031 = LHORMENS;
rename	SALM031E = LSALMENSE;
rename	SALM03E = SALMENSE;
rename	salhor03 = SALHOR;
rename	lsalhor03 = LSALHOR;
rename	lnsalhor03 = LNSALHOR;
rename	dlnsalhor03 = DLNSALHOR;
rename	indic_chgt_salhor03 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor03_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor03_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor03 = INDICABERHOR;
rename	indichor03 = INDICHOR;
rename	lindichor03 = LINDICHOR;
rename	lnsalmens03 = LNSALMENSE;
rename	dlnsalmens03 = DLNSALMENSE;
rename	indicmens03 = INDICMENS	;
rename	lindicmens03 = LINDICMENS;
rename	indic_chgt_salmens03 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens03_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens03_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens03 = INDICABERMENS	;
rename  ISALM03 = ISALM;
rename  pcatEntSect03 = PCATENTSECT;

CAT='cat03';
run;

/* CAT04 */
data ecriture.cat04;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR  PREST1
R_RETOUR NUMERO
HORM04 HORM041 SALM04 SALM04E SALM041 SALM041E 
salhor04 lsalhor04 lnsalhor04 dlnsalhor04 indichor04 lindichor04 indicaberhor04
indic_chgt_salhor04 indic_chgt_salhor04_nega indic_chgt_salhor04_posi 
lnsalmens04 dlnsalmens04
indic_chgt_salmens04 indic_chgt_salmens04_nega indic_chgt_salmens04_posi    
indicmens04 lindicmens04 indicabermens04
ISALM04 ISALMEMP ISALMTOT PEMP PTOT pcatEntSect04  ;
run;
data ecriture.cat04;set ecriture.cat04;
rename	SALM04 = SALMENS;
rename	SALM041 = LSALMENS;
rename	HORM04 = HORMENS;
rename	HORM041 = LHORMENS;
rename	SALM041E = LSALMENSE;
rename	SALM04E = SALMENSE;
rename	salhor04 = SALHOR;
rename	lsalhor04 = LSALHOR;
rename	lnsalhor04 = LNSALHOR;
rename	dlnsalhor04 = DLNSALHOR;
rename	indic_chgt_salhor04 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor04_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor04_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor04 = INDICABERHOR;
rename	indichor04 = INDICHOR;
rename	lindichor04 = LINDICHOR;
rename	lnsalmens04 = LNSALMENSE;
rename	dlnsalmens04 = DLNSALMENSE;
rename	indicmens04 = INDICMENS	;
rename	lindicmens04 = LINDICMENS;
rename	indic_chgt_salmens04 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens04_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens04_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens04 = INDICABERMENS	;
rename  ISALM04 = ISALM;
rename  pcatEntSect04 = PCATENTSECT;

CAT='cat04';
run;

/* CAT05 */
data ecriture.cat05;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR  PREST1
R_RETOUR NUMERO
HORM05 HORM051 SALM05 SALM05E SALM051 SALM051E 
salhor05 lsalhor05 lnsalhor05 dlnsalhor05 indichor05 lindichor05 indicaberhor05
indic_chgt_salhor05 indic_chgt_salhor05_nega indic_chgt_salhor05_posi 
lnsalmens05 dlnsalmens05
indic_chgt_salmens05 indic_chgt_salmens05_nega indic_chgt_salmens05_posi    
indicmens05 lindicmens05 indicabermens05
ISALM05 ISALMEMP ISALMTOT PEMP PTOT pcatEntSect05;
run;
data ecriture.cat05;set ecriture.cat05;
rename	SALM05 = SALMENS;
rename	SALM051 = LSALMENS;
rename	HORM05 = HORMENS;
rename	HORM051 = LHORMENS;
rename	SALM051E = LSALMENSE;
rename	SALM05E = SALMENSE;
rename	salhor05 = SALHOR;
rename	lsalhor05 = LSALHOR;
rename	lnsalhor05 = LNSALHOR;
rename	dlnsalhor05 = DLNSALHOR;
rename	indic_chgt_salhor05 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor05_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor05_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor05 = INDICABERHOR;
rename	indichor05 = INDICHOR;
rename	lindichor05 = LINDICHOR;
rename	lnsalmens05 = LNSALMENSE;
rename	dlnsalmens05 = DLNSALMENSE;
rename	indicmens05 = INDICMENS	;
rename	lindicmens05 = LINDICMENS;
rename	indic_chgt_salmens05 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens05_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens05_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens05 = INDICABERMENS	;
rename  ISALM05 = ISALM;
rename  pcatEntSect05 = PCATENTSECT;

CAT='cat05';
run;

/* CAT06 */
data ecriture.cat06;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT N N16 N36 NES16 NICGR PREST1
R_RETOUR NUMERO
HORM06 HORM061 SALM06 SALM06E SALM061 SALM061E 
salhor06 lsalhor06 lnsalhor06 dlnsalhor06 indichor06 lindichor06 indicaberhor06
indic_chgt_salhor06 indic_chgt_salhor06_nega indic_chgt_salhor06_posi 
lnsalmens06 dlnsalmens06
indic_chgt_salmens06 indic_chgt_salmens06_nega indic_chgt_salmens06_posi    
indicmens06 lindicmens06 indicabermens06
ISALM06 ISALMEMP ISALMTOT PEMP PTOT pcatEntSect06 ;
run;
data ecriture.cat06;set ecriture.cat06;
rename	SALM06 = SALMENS;
rename	SALM061 = LSALMENS;
rename	HORM06 = HORMENS;
rename	HORM061 = LHORMENS;
rename	SALM061E = LSALMENSE;
rename	SALM06E = SALMENSE;
rename	salhor06 = SALHOR;
rename	lsalhor06 = LSALHOR;
rename	lnsalhor06 = LNSALHOR;
rename	dlnsalhor06 = DLNSALHOR;
rename	indic_chgt_salhor06 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor06_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor06_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor06 = INDICABERHOR;
rename	indichor06 = INDICHOR;
rename	lindichor06 = LINDICHOR;
rename	lnsalmens06 = LNSALMENSE;
rename	dlnsalmens06 = DLNSALMENSE;
rename	indicmens06 = INDICMENS	;
rename	lindicmens06 = LINDICMENS;
rename	indic_chgt_salmens06 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens06_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens06_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens06 = INDICABERMENS	;
rename  ISALM06 = ISALM;
rename  pcatEntSect06 = PCATENTSECT;

CAT='cat06';
run;

/* CAT07 */
data ecriture.cat07;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR  PREST1
R_RETOUR NUMERO
HORM07 HORM071 SALM07 SALM07E SALM071 SALM071E 
salhor07 lsalhor07 lnsalhor07 dlnsalhor07 indichor07 lindichor07 indicaberhor07
indic_chgt_salhor07 indic_chgt_salhor07_nega indic_chgt_salhor07_posi 
lnsalmens07 dlnsalmens07
indic_chgt_salmens07 indic_chgt_salmens07_nega indic_chgt_salmens07_posi    
indicmens07 lindicmens07 indicabermens07
ISALM07 ISALMPIN ISALMTOT PPIN PTOT pcatEntSect07 ;
run;
data ecriture.cat07;set ecriture.cat07;
rename	SALM07 = SALMENS;
rename	SALM071 = LSALMENS;
rename	HORM07 = HORMENS;
rename	HORM071 = LHORMENS;
rename	SALM071E = LSALMENSE;
rename	SALM07E = SALMENSE;
rename	salhor07 = SALHOR;
rename	lsalhor07 = LSALHOR;
rename	lnsalhor07 = LNSALHOR;
rename	dlnsalhor07 = DLNSALHOR;
rename	indic_chgt_salhor07 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor07_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor07_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor07 = INDICABERHOR;
rename	indichor07 = INDICHOR;
rename	lindichor07 = LINDICHOR;
rename	lnsalmens07 = LNSALMENSE;
rename	dlnsalmens07 = DLNSALMENSE;
rename	indicmens07 = INDICMENS	;
rename	lindicmens07 = LINDICMENS;
rename	indic_chgt_salmens07 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens07_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens07_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens07 = INDICABERMENS	;
rename  ISALM07 = ISALM;
rename  pcatEntSect07 = PCATENTSECT;

CAT='cat07';
run;

/* CAT08 */
data ecriture.cat08;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR PREST1
R_RETOUR NUMERO
HORM08 HORM081 SALM08 SALM08E SALM081 SALM081E 
salhor08 lsalhor08 lnsalhor08 dlnsalhor08 indichor08 lindichor08 indicaberhor08
indic_chgt_salhor08 indic_chgt_salhor08_nega indic_chgt_salhor08_posi 
lnsalmens08 dlnsalmens08
indic_chgt_salmens08 indic_chgt_salmens08_nega indic_chgt_salmens08_posi    
indicmens08 lindicmens08 indicabermens08
ISALM08 ISALMPIN ISALMTOT PPIN PTOT pcatEntSect08 ;
run;
data ecriture.cat08;set ecriture.cat08;
rename	SALM08 = SALMENS;
rename	SALM081 = LSALMENS;
rename	HORM08 = HORMENS;
rename	HORM081 = LHORMENS;
rename	SALM081E = LSALMENSE;
rename	SALM08E = SALMENSE;
rename	salhor08 = SALHOR;
rename	lsalhor08 = LSALHOR;
rename	lnsalhor08 = LNSALHOR;
rename	dlnsalhor08 = DLNSALHOR;
rename	indic_chgt_salhor08 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor08_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor08_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor08 = INDICABERHOR;
rename	indichor08 = INDICHOR;
rename	lindichor08 = LINDICHOR;
rename	lnsalmens08 = LNSALMENSE;
rename	dlnsalmens08 = DLNSALMENSE;
rename	indicmens08 = INDICMENS	;
rename	lindicmens08 = LINDICMENS;
rename	indic_chgt_salmens08 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens08_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens08_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens08 = INDICABERMENS	;
rename  ISALM08 = ISALM;
rename  pcatEntSect08 = PCATENTSECT;

CAT='cat08';
run;

/* CAT09 */
data ecriture.cat09;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR  PREST1
R_RETOUR NUMERO
HORM09 HORM091 SALM09 SALM09E SALM091 SALM091E 
salhor09 lsalhor09 lnsalhor09 dlnsalhor09 indichor09 lindichor09 indicaberhor09
indic_chgt_salhor09 indic_chgt_salhor09_nega indic_chgt_salhor09_posi 
lnsalmens09 dlnsalmens09
indic_chgt_salmens09 indic_chgt_salmens09_nega indic_chgt_salmens09_posi    
indicmens09 lindicmens09 indicabermens09
ISALM09 ISALMPIN ISALMTOT PPIN PTOT pcatEntSect09 ;
run;
data ecriture.cat09;set ecriture.cat09;
rename	SALM09 = SALMENS;
rename	SALM091 = LSALMENS;
rename	HORM09 = HORMENS;
rename	HORM091 = LHORMENS;
rename	SALM091E = LSALMENSE;
rename	SALM09E = SALMENSE;
rename	salhor09 = SALHOR;
rename	lsalhor09 = LSALHOR;
rename	lnsalhor09 = LNSALHOR;
rename	dlnsalhor09 = DLNSALHOR;
rename	indic_chgt_salhor09 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor09_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor09_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor09 = INDICABERHOR;
rename	indichor09 = INDICHOR;
rename	lindichor09 = LINDICHOR;
rename	lnsalmens09 = LNSALMENSE;
rename	dlnsalmens09 = DLNSALMENSE;
rename	indicmens09 = INDICMENS	;
rename	lindicmens09 = LINDICMENS;
rename	indic_chgt_salmens09 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens09_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens09_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens09 = INDICABERMENS	;
rename  ISALM09 = ISALM;
rename  pcatEntSect09 = PCATENTSECT;

CAT='cat09';
run;

/* CAT10 */
data ecriture.cat10;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR  PREST1
R_RETOUR NUMERO
HORM10 HORM101 SALM10 SALM10E SALM101 SALM101E 
salhor10 lsalhor10 lnsalhor10 dlnsalhor10 indichor10 lindichor10 indicaberhor10
indic_chgt_salhor10 indic_chgt_salhor10_nega indic_chgt_salhor10_posi 
lnsalmens10 dlnsalmens10
indic_chgt_salmens10 indic_chgt_salmens10_nega indic_chgt_salmens10_posi    
indicmens10 lindicmens10 indicabermens10
ISALM10 ISALMCAD ISALMTOT PCAD PTOT pcatEntSect10 ;
run;
data ecriture.cat10;set ecriture.cat10;
rename	SALM10 = SALMENS;
rename	SALM101 = LSALMENS;
rename	HORM10 = HORMENS;
rename	HORM101 = LHORMENS;
rename	SALM101E = LSALMENSE;
rename	SALM10E = SALMENSE;
rename	salhor10 = SALHOR;
rename	lsalhor10 = LSALHOR;
rename	lnsalhor10 = LNSALHOR;
rename	dlnsalhor10 = DLNSALHOR;
rename	indic_chgt_salhor10 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor10_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor10_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor10 = INDICABERHOR;
rename	indichor10 = INDICHOR;
rename	lindichor10 = LINDICHOR;
rename	lnsalmens10 = LNSALMENSE;
rename	dlnsalmens10 = DLNSALMENSE;
rename	indicmens10 = INDICMENS	;
rename	lindicmens10 = LINDICMENS;
rename	indic_chgt_salmens10 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens10_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens10_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens10 = INDICABERMENS	;
rename  ISALM10 = ISALM;
rename  pcatEntSect10 = PCATENTSECT;

CAT='cat10';
run;

/* CAT11 */
data ecriture.cat11;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR  PREST1
R_RETOUR NUMERO
HORM11 HORM111 SALM11 SALM11E SALM111 SALM111E 
salhor11 lsalhor11 lnsalhor11 dlnsalhor11 indichor11 lindichor11 indicaberhor11
indic_chgt_salhor11 indic_chgt_salhor11_nega indic_chgt_salhor11_posi 
lnsalmens11 dlnsalmens11
indic_chgt_salmens11 indic_chgt_salmens11_nega indic_chgt_salmens11_posi    
indicmens11 lindicmens11 indicabermens11
ISALM11 ISALMCAD ISALMTOT PCAD PTOT pcatEntSect11 ;
run;
data ecriture.cat11;set ecriture.cat11;
rename	SALM11 = SALMENS;
rename	SALM111 = LSALMENS;
rename	HORM11 = HORMENS;
rename	HORM111 = LHORMENS;
rename	SALM111E = LSALMENSE;
rename	SALM11E = SALMENSE;
rename	salhor11 = SALHOR;
rename	lsalhor11 = LSALHOR;
rename	lnsalhor11 = LNSALHOR;
rename	dlnsalhor11 = DLNSALHOR;
rename	indic_chgt_salhor11 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor11_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor11_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor11 = INDICABERHOR;
rename	indichor11 = INDICHOR;
rename	lindichor11 = LINDICHOR;
rename	lnsalmens11 = LNSALMENSE;
rename	dlnsalmens11 = DLNSALMENSE;
rename	indicmens11 = INDICMENS	;
rename	lindicmens11 = LINDICMENS;
rename	indic_chgt_salmens11 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens11_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens11_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens11 = INDICABERMENS	;
rename  ISALM11 = ISALM;
rename  pcatEntSect11 = PCATENTSECT;

CAT='cat11';
run;

/* CAT12 */
data ecriture.cat12;set ecriture.ACEMO_SALHOR_SALMENS;
keep
SIRET C_APETD C_TEFEND DATE date_poids datea EFFSIR EFFTOT  N N16 N36 NES16 NICGR  PREST1
R_RETOUR NUMERO
HORM12 HORM121 SALM12 SALM12E SALM121 SALM121E 
salhor12 lsalhor12 lnsalhor12 dlnsalhor12 indichor12 lindichor12 indicaberhor12
indic_chgt_salhor12 indic_chgt_salhor12_nega indic_chgt_salhor12_posi 
lnsalmens12 dlnsalmens12
indic_chgt_salmens12 indic_chgt_salmens12_nega indic_chgt_salmens12_posi    
indicmens12 lindicmens12 indicabermens12
ISALM12 ISALMCAD ISALMTOT PCAD PTOT pcatEntSect12 ;
run;
data ecriture.cat12;set ecriture.cat12;
rename	SALM12 = SALMENS;
rename	SALM121 = LSALMENS;
rename	HORM12 = HORMENS;
rename	HORM121 = LHORMENS;
rename	SALM121E = LSALMENSE;
rename	SALM12E = SALMENSE;
rename	salhor12 = SALHOR;
rename	lsalhor12 = LSALHOR;
rename	lnsalhor12 = LNSALHOR;
rename	dlnsalhor12 = DLNSALHOR;
rename	indic_chgt_salhor12 = INDIC_CHGT_SALHOR;
rename	indic_chgt_salhor12_nega = INDIC_CHGT_SALHOR_NEGA;
rename	indic_chgt_salhor12_posi = INDIC_CHGT_SALHOR_POSI;
rename	indicaberhor12 = INDICABERHOR;
rename	indichor12 = INDICHOR;
rename	lindichor12 = LINDICHOR;
rename	lnsalmens12 = LNSALMENSE;
rename	dlnsalmens12 = DLNSALMENSE;
rename	indicmens12 = INDICMENS	;
rename	lindicmens12 = LINDICMENS;
rename	indic_chgt_salmens12 = INDIC_CHGT_SALMENS	;
rename	indic_chgt_salmens12_nega = INDIC_CHGT_SALMENS_NEGA	;
rename	indic_chgt_salmens12_posi = INDIC_CHGT_SALMENS_POSI	;
rename	indicabermens12 = INDICABERMENS	;
rename  ISALM12 = ISALM;
rename  pcatEntSect12 = PCATENTSECT;

CAT='cat12';
run;


/* on fusionne les bases par cat�gorie*/
data ecriture.acemo_transpo;
set ecriture.cat01
	ecriture.cat02
	ecriture.cat03
	ecriture.cat04
	ecriture.cat05
	ecriture.cat06
	ecriture.cat07
	ecriture.cat08
	ecriture.cat09
	ecriture.cat10
	ecriture.cat11
	ecriture.cat12;
	run;
proc sort data = ecriture.acemo_transpo;by siret cat date;run;
proc contents data=ecriture.acemo_transpo;run;



/************************************************************************************/
/***************         VII - CREATION DE VARIABLES             ********************/
/************************************************************************************/


/********************/
/* CREATION DES CSP */
/********************/
data ecriture.acemo_transpo_csp;set ecriture.acemo_transpo;
csp='csp';
if cat in ('cat01', 'cat02', 'cat03') then csp='OUV';
if cat in ('cat04', 'cat05', 'cat06') then csp='EMP';
if cat in ('cat07', 'cat08', 'cat09') then csp='PRI';
if cat in ('cat10', 'cat11', 'cat12') then csp='CAD';
run;
/* v�rif. que la variable CSP est toujours renseign�e : OK */
/*proc print data=ecriture.acemo_transpo_csp (where= (csp not in ('OUV','EMP','PRI','CAD')));run;*/

/*************************************/
/* CREATION DE CLASSES D'EFFECTIFS   */
/* LE 17/11/06 : modif de classe_eff */
/* par LB suite dde HLB+JM           */
/* LE 22/11/06 : modif de classe_eff */
/* CONSTANTE POUR UN MEME SIRET      */
/* SUR TOUTE LA PERIODE              */
/* par LB suite dde TH               */
/*************************************/
/* LE 22 NOV. 2006 */
/* EFFTOT EST AFFECTEE A 1 SIRET A UNE DATE DONNEE ET NE VARIE PAS EN FONCTION DE LA CATEGORIE */
/* on ne garde qu'un efftot diff�rent de . par siret et par date  */
data apure_point(keep = siret date efftot); 
set ecriture.acemo_transpo_csp(where=(efftot ne .));run;
proc sort data=apure_point out=apure nodupkeys ;by siret date;run;

/* on fait la moyenne des efftot par siret sur la p�riode */
proc univariate data=apure noprint;
output out=efftot_moy mean=efftot_moy;
var efftot;by siret;run;

/* pour 1 siret donn�, on calcule � partir de efftot_moy un classe_eff d�finitif
   qui sera identique pour toutes les ann�es */
data ecriture.efftot_moy_classe; set efftot_moy;
format classe_eff $9. ;
if efftot_moy = .                      	   then classe_eff='inconnu';
if efftot_moy lt 0 and efftot_moy ne .     then classe_eff='negatif';
if efftot_moy ge 0 and efftot_moy  lt 20   then classe_eff='0 � 19';
if efftot_moy ge 20 and efftot_moy lt 50   then classe_eff='20 � 49';
if efftot_moy ge 50 and efftot_moy lt 150  then classe_eff='50 � 149';
if efftot_moy ge 150 and efftot_moy lt 500 then classe_eff='150 � 499';
if efftot_moy ge 500                       then classe_eff='+ de 500';
run;

title 'proc freq ecriture.efftot_moy_classe ';
proc freq data=ecriture.efftot_moy_classe;table classe_eff;run;

/* int�gration dans la base de la variable classe_eff */ 
/* pour les siret dont efftot est toujours � point, classe_eff='inconnu' */ 
data ecriture.acemo_transpo_eff;
merge ecriture.acemo_transpo_csp(in=in1) ecriture.efftot_moy_classe(drop=efftot_moy);
if in1;by siret;run;

data ecriture.acemo_transpo_eff; set ecriture.acemo_transpo_eff;
if classe_eff='         ' then classe_eff='inconnu';run;

title 'proc freq ecriture.acemo_transpo_eff ';
proc freq data=ecriture.acemo_transpo_eff;table classe_eff;run;
title '   ';

/*************************************/
/* CREATION D'UNE VARIABLE TRIMESTRE */
/*************************************/
data ecriture.acemo_transpo_trim; set ecriture.acemo_transpo_eff;
trim=date-int(date);
if trim = 0    then trimestre = 1;
if trim = 0.25 then trimestre = 2;
if trim = 0.50 then trimestre = 3;
if trim = 0.75 then trimestre = 4;
drop trim;run;
/*proc freq data=ecriture.acemo_transpo_trim;table trimestre;run;*/


/****************************************/
/* INTEGRATION DE LA SERIE DE SMIC      */
/* s�rie trait�e par J�r�mi             */
/****************************************/

data ecriture.smictrim;set lect4.smictrim_JM;
drop date;
run;
data ecriture.smictrim;set ecriture.smictrim;
date=date2;
drop date2 ;
run;

proc sort data=ecriture.acemo_transpo_trim out=acemo_transpo_trim ;by date;run;
data ecriture.base_acemo_transpo; 
merge acemo_transpo_trim (in=in1)
	  ecriture.smictrim;
by date;
if in1;
run;

data ecriture.base_acemo_transpo; set ecriture.base_acemo_transpo; 
drop N date_poids datea isalmouv isalmemp isalmpin isalmcad pouv pemp ppin pcad N16 N36;
run;	


/*****************************************/
/* CREATION DE LA VARIABLE SECTEUR       */
/* INDUSTRIE  :   1                      */
/* CONSTRUCTION : 2                      */
/* COMMERCE  :    3                      */
/* NB : EG fait bien partie du secteur 1 */
/*****************************************/
data ecriture.base_acemo_transpo; set ecriture.base_acemo_transpo;
format SECTEUR $1. ; 
if NES16 in ('EB','EC','ED','EE','EF','EG') then SECTEUR = '1';
if NES16 in ('EH') then SECTEUR = '2';
if NES16 in ('EJ','EK','EL','EM','EN','EP','EQ','ER') then SECTEUR = '3';
run;
/*proc contents data=ecriture.base_acemo_transpo;run;*/

/***********************************/
/* NORMALISATION DES POIDS A 100   */
/***********************************/
proc summary data=ecriture.base_acemo_transpo; output out=resu sum=somme;
var pcatentsect;by date;run;
data resu; set resu; keep date somme;run;
proc sort data=ecriture.base_acemo_transpo out=ecriture.acemo_transpo_tri_date;by date;run;
data ecriture.base_acemo_finale;merge ecriture.acemo_transpo_tri_date(in=in1) resu ;
if in1;by date;run;
data ecriture.base_acemo_finale; set ecriture.base_acemo_finale;
POIDS=100*pcatentsect/somme;
drop somme;run;
/*proc contents data=ecriture.base_acemo_finale;run;*/

proc summary data=ecriture.base_acemo_finale; output out=test sum=somme;
var poids;by date;run;


/************************************************************************************/
/*                         CREATION D'UNE BASE REDUITE                              */
/************************************************************************************/
/* suppression des observations telles que hormens=. et salmens =.  */
/* le nombre d'observations tel que salmens=. est de 8467998        */
/* le nombre d'observations tel que salmensE=. est de 8467998       */
/* utiliser l'une ou l'autre variable doit revenir au m�me...       */  
data ecriture.base_acemo_reduite; 
set ecriture.base_acemo_finale (where= (hormens ne . and salmens ne .)); run; 
/* 4 571 627 obs */

/******************************************************/
/* CREATION DANS BASE_ACEMO_REDUITE                   */
/* D'UNE INDICATRICE EN VUE D'EXCLURE LES             */ 
/* VALEURS ABERRANTES NON REPEREES PAR INDICABERMENS  */
/* INDICABERMENS_NEW = 0 PAR DEFAUT                   */
/* INDICABERMENS_NEW = 1 OU 2 : VALEUR ABERRANTE      */
/******************************************************/
data ecriture.base_acemo_reduite;set ecriture.base_acemo_reduite;
indicabermens_new = 0;
if dlnsalmense = . and lsalmense = 0 then indicabermens_new = 1;
if dlnsalmense = . and lsalmense = . and isalm = . then indicabermens_new = 2;
run; 
proc contents data=ecriture.base_acemo_reduite;run;

/*proc freq data=ecriture.base_acemo_reduite;table classe_eff;run; 
data verif; set ecriture.base_acemo_reduite(where=(classe_eff = 'inconnu'));
keep siret date efftot classe_eff;run;*/



/*********************************************************************************/
/*               NOUVELLES VARIABLES INTEGREES A BASE_ACEMO_REDUITE              */  
/*                                                                               */   
/********************* TAUX DE CHOMAGE NATIONAL : TXCHOM_NAT  ********************/
/********************* TAUX DE CHOMAGE DEPARTEMENTAL : TXCHOM ********************/
/********************* INDICE DES PRIX A LA CONSO NATIONAL : IPCN ****************/
/*                                                                               */
/*   ST le 11/01/2007                                                            */
/*********************************************************************************/ 


/************ Fichier du ch�mage par d�partement *************************/
proc sort data=lect5.chomage ; by dep;run;
/* transposition de la table */
proc transpose data=lect.chomage out=ecriture.chomage_transpo ;
var V31_12_1998 
V31_03_1999 V30_06_1999 V30_09_1999 V31_12_1999
V31_03_2000 V30_06_2000 V30_09_2000 V31_12_2000
V31_03_2001 V30_06_2001 V30_09_2001 V31_12_2001
V31_03_2002 V30_06_2002 V30_09_2002 V31_12_2002
V31_03_2003 V30_06_2003 V30_09_2003 V31_12_2003
V31_03_2004 V30_06_2004 V30_09_2004 V31_12_2004
V31_03_2005 V30_06_2005 V30_09_2005 V31_12_2005
;
by dep nomdep ;run;
data ecriture.chomage_transpo_rename ; set ecriture.chomage_transpo;
format date best12.;length date 3;
txchom=col1;
if _name_='V31_12_1998' then date = 1998.75;
if _name_='V31_03_1999' then date = 1999.00;
if _name_="V30_06_1999" then date = 1999.25;
if _name_="V30_09_1999" then date = 1999.50;
if _name_="V31_12_1999" then date = 1999.75;
if _name_="V31_03_2000" then date = 2000.00;
if _name_="V30_06_2000" then date = 2000.25;
if _name_="V30_09_2000" then date = 2000.50;
if _name_="V31_12_2000" then date = 2000.75;
if _name_="V31_03_2001" then date = 2001.00;
if _name_="V30_06_2001" then date = 2001.25;
if _name_="V30_09_2001" then date = 2001.50;
if _name_="V31_12_2001" then date = 2001.75;
if _name_="V31_03_2002" then date = 2002.00;
if _name_="V30_06_2002" then date = 2002.25;
if _name_="V30_09_2002" then date = 2002.50;
if _name_="V31_12_2002" then date = 2002.75;
if _name_="V31_03_2003" then date = 2003.00;
if _name_="V30_06_2003" then date = 2003.25;
if _name_="V30_09_2003" then date = 2003.50;
if _name_="V31_12_2003" then date = 2003.75;
if _name_="V31_03_2004" then date = 2004.00;
if _name_="V30_06_2004" then date = 2004.25;
if _name_="V30_09_2004" then date = 2004.50;
if _name_="V31_12_2004" then date = 2004.75;
if _name_="V31_03_2005" then date = 2005.00;
if _name_="V30_06_2005" then date = 2005.25;
if _name_="V30_09_2005" then date = 2005.50;
if _name_="V31_12_2005" then date = 2005.75;
drop col1 _name_;run;
/* fichier contenant les d�partements */
data ecriture.dep;set lect4.acemo_dep_060524;
rename s_et = numero;
run;
/* fusion de BASE_ACEMO_REDUITE avec le fichier des d�partements*/
proc sort data=ecriture.base_acemo_reduite out=base_acemo_reduite_tri;by numero siret date;run;
proc sort data=ecriture.dep;by numero;run;
data base_acemo_reduite_dep;
merge base_acemo_reduite_tri (in=in1) 
	  ecriture.dep;
	  by numero ;
	  if in1;
	  run;
/****** fusion de BASE_ACEMO_REDUITE avec la table du taux de ch�mage d�partemental ***********/
proc sort data=base_acemo_reduite_dep ;by dep date;run;
proc sort data=ecriture.chomage_transpo_rename;by dep date;run;
data ecriture.base_acemo_reduite_2;
merge base_acemo_reduite_dep (in=in1)
	  ecriture.chomage_transpo_rename;
	  by DEP DATE;
	  if in1;
	  run;
proc contents data=ecriture.base_acemo_reduite_2;run;
/* verif. */
proc print data=ecriture.base_acemo_reduite_2 (where=(dep=' '));
var numero siret numero dep txchom ;run;/* 45 obs */
proc print data=ecriture.base_acemo_reduite_2 (where=(dep='00'));
var numero siret numero dep txchom ;run;/* 69 obs */
proc print data=ecriture.base_acemo_reduite_2 (where=(txchom=.));
var numero siret numero dep txchom ;run;/* 1847 obs */
proc print data=ecriture.chomage_transpo_rename (where=(dep=' ' or dep='00'));
run;/* o obs */


/************ Fichier du ch�mage national *************************/
/* transposition de la table */
proc transpose data=lect6.chomage_national out=ecriture.chomage_nat_transpo ;
var V31_12_1998 
V31_03_1999 V30_06_1999 V30_09_1999 V31_12_1999
V31_03_2000 V30_06_2000 V30_09_2000 V31_12_2000
V31_03_2001 V30_06_2001 V30_09_2001 V31_12_2001
V31_03_2002 V30_06_2002 V30_09_2002 V31_12_2002
V31_03_2003 V30_06_2003 V30_09_2003 V31_12_2003
V31_03_2004 V30_06_2004 V30_09_2004 V31_12_2004
V31_03_2005 V30_06_2005 V30_09_2005 V31_12_2005
;
run;
data ecriture.chomage_nat_transpo_rename ; set ecriture.chomage_nat_transpo;
format date best12.;length date 3;
txchom_nat=col1;
if _name_='V31_12_1998' then date = 1998.75;
if _name_='V31_03_1999' then date = 1999.00;
if _name_="V30_06_1999" then date = 1999.25;
if _name_="V30_09_1999" then date = 1999.50;
if _name_="V31_12_1999" then date = 1999.75;
if _name_="V31_03_2000" then date = 2000.00;
if _name_="V30_06_2000" then date = 2000.25;
if _name_="V30_09_2000" then date = 2000.50;
if _name_="V31_12_2000" then date = 2000.75;
if _name_="V31_03_2001" then date = 2001.00;
if _name_="V30_06_2001" then date = 2001.25;
if _name_="V30_09_2001" then date = 2001.50;
if _name_="V31_12_2001" then date = 2001.75;
if _name_="V31_03_2002" then date = 2002.00;
if _name_="V30_06_2002" then date = 2002.25;
if _name_="V30_09_2002" then date = 2002.50;
if _name_="V31_12_2002" then date = 2002.75;
if _name_="V31_03_2003" then date = 2003.00;
if _name_="V30_06_2003" then date = 2003.25;
if _name_="V30_09_2003" then date = 2003.50;
if _name_="V31_12_2003" then date = 2003.75;
if _name_="V31_03_2004" then date = 2004.00;
if _name_="V30_06_2004" then date = 2004.25;
if _name_="V30_09_2004" then date = 2004.50;
if _name_="V31_12_2004" then date = 2004.75;
if _name_="V31_03_2005" then date = 2005.00;
if _name_="V30_06_2005" then date = 2005.25;
if _name_="V30_09_2005" then date = 2005.50;
if _name_="V31_12_2005" then date = 2005.75;
drop col1 _name_;run;
/*********** fusion de BASE_ACEMO_REDUITE_2 avec la table du taux de ch�mage national***********/
proc sort data=ecriture.base_acemo_reduite_2 ;by date;run;
proc sort data=ecriture.chomage_nat_transpo_rename;by date;run;
data ecriture.base_acemo_reduite_3;
merge ecriture.base_acemo_reduite_2 (in=in1)
	  ecriture.chomage_nat_transpo_rename;
	  by DATE;
	  if in1;
	  run;


/************************************************************************************/
/************************    INTEGRATION DE L'IPCN      *****************************/
/************************************************************************************/
data ecriture.ipcn ; set lect6.ipcn_trim;
format ipcn best12.;length ipcn 3;
format date best12.;length date 3;
run;
/*********** fusion de BASE_ACEMO_REDUITE_3 avec la table IPCN ***********/
proc sort data=ecriture.base_acemo_reduite_3 ;by date;run;
proc sort data=ecriture.ipcn;by date;run;
data ecriture.base_acemo_reduite_4;
merge ecriture.base_acemo_reduite_3 (in=in1)
	  ecriture.ipcn;
	  by DATE;
	  if in1;
	  run;
proc sort data=ecriture.base_acemo_reduite_4 ;by siret date;run;
proc contents data=ecriture.base_acemo_reduite_4;run;

/* verif. */
proc print data=ecriture.base_acemo_reduite_4 (where=(dep=' '));
var numero siret numero dep txchom ;run;/* 45 obs */
proc print data=ecriture.base_acemo_reduite_4 (where=(dep='00'));
var numero siret numero dep txchom ;run;/* 69 obs */
proc print data=ecriture.base_acemo_reduite_4 (where=(txchom=.));
var numero siret numero dep txchom ;run;/* 1847 obs */
proc print data=ecriture.chomage_transpo_rename (where=(dep=' ' or dep='00'));
run;/* o obs */


/******************************************************************************************/
/*  INTEGRATION D'UNE INDICATRICE DE PREMIER CHANGEMENT DE SALAIRE DE L'ANNEE :           */
/*                         PREMIER_CHGT � partir de DLNSALMENSE                           */
/* ST le 18/01/07                                                                         */
/******************************************************************************************/

/* CREATION DE LA VARIABLE ANNEE */
data ecriture.base_acemo_reduite_5;set ecriture.base_acemo_reduite_4 ;
ANNEE = int(DATE);
run;
proc sort data = ecriture.base_acemo_reduite_5; by SIRET CAT ANNEE TRIMESTRE; run;

/* on ne garde que la premi�re ann�e et on lui affecte 1 pour l'indicatrice PREMIER_CHGT  */
data ecriture.PREMIER_CHGT; set ecriture.base_acemo_reduite_5 (keep=SIRET CAT ANNEE TRIMESTRE ISALM DLNSALMENSE SALMENSE LSALMENSE where=(DLNSALMENSE not in(0,.))); 
	by SIRET CAT ANNEE TRIMESTRE; 
	if first.ANNEE; 
	PREMIER_CHGT= 1;
	run;

data ecriture.base_acemo_reduite_6;
	merge ecriture.base_acemo_reduite_5 
		  ecriture.PREMIER_CHGT(keep=SIRET CAT ANNEE TRIMESTRE PREMIER_CHGT);  
	by SIRET CAT ANNEE TRIMESTRE; 
	if PREMIER_CHGT ne 1  then PREMIER_CHGT = 0; 
	run; 

	
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/****************** DERNIERE BASE CREEE / BASE_ACEMO_REDUITE_6  ****************************/
/*                               4 571 627 obs                                             */
/* le 18/01/2007 */
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/******************************************************************/
/* INTEGRATION DANS BASE_ACEMO_REDUITE_6 DE 5 NOUVELLES VARIABLES */
/* ON VA CHERCHER COMPL_1999_2006 DANS                            */
/* W:\ACEMO\PROJET_ACEMO\BASE_INITIALE\donnees_compl              */ 
/* LE PRG DE CREATION DE LA BASE CI-DESSUS EST :                  */
/* W:\ACEMO\PROJET_ACEMO\PROGRAMMES\BASE_INITIALE\donnees_compl\  */
/* BASE_AVEC_DONNEES_COMPL.SAS                                    */
/* PAS DE DOUBLONS SIRET / DATE DANS COMPL_1999_2006              */  
/******************************************************************/
proc sort data=ecriture.base_acemo_reduite_6; by siret date;run;
proc sort data=compl.COMPL_1999_2006; by siret date;run;

data ecriture.base_acemo_reduite_7;
merge ecriture.base_acemo_reduite_6(in=in1) compl.COMPL_1999_2006;
if in1; by siret date;run;

proc contents data=ecriture.base_acemo_reduite_7;run;



/***************************************************************/
/* CREATION D'UNE INDICATRICE REPERANT LES RTT : INDIC_RTT     */
/* LB-JM le 23/05/07                                           */
/* recalcul�e le 18 juin 2007                                  */
/***************************************************************/
/* 1ere indicatrice RTT : ne sert plus */
/*
data ecriture.base_acemo_reduite_8; set ecriture.base_acemo_reduite_7;
TX_HORMENS=(HORMENS/LHORMENS-1)*100;
INDIC_RTT=0;
IF TX_HORMENS le -10 and TX_HORMENS ne . and TX_HORMENS ge -15 then INDIC_RTT=1;
run;
*/

/**!!!!!!!!!!!!! REFAIRE TOURNER D'ICI !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/

/***************************************************************************/
/* NOUVELLE INDICATRICE DE RTT - CALCUL DU LAG_HORMENS                     */
/***************************************************************************/
data ecriture.base_acemo_reduite_8; set ecriture.base_acemo_reduite_7;
lsiret=lag(siret);
lcat=lag(cat);
lag_hormens=.;
delhormens=lag(hormens);
if siret=lsiret and cat=lcat then lag_hormens=delhormens;
INDIC_RTT=0;
IF (hormens le 152 and hormens ge 140) and (lag_hormens ge 165) then INDIC_RTT=1;
run;
data ecriture.base_acemo_reduite_8; set ecriture.base_acemo_reduite_8;
drop lsiret lcat lag_hormens delhormens;run;

/******************************************************************************************/
/* INTEGRATION DES IPC REGIONAUX                                                          */
/* issus du programme w:\acemo\projet_acemo\programmes\lecture_ipc_regionaux_jm.sas       */
/* ST le 31/05/2007                                                                    */
/******************************************************************************************/

/* fusion de base_acemo_reduite_8 et tab_passage_dep_reg pour avoir les r�gions */
proc sort data=ecriture.base_acemo_reduite_8 out=ecriture.base_acemo_reduite_8_tri;by dep annee trimestre;run;
proc sort data=lect7.tab_passage_dep_reg;by DEP;run;
data ecriture.base_acemo_reduite_9;
merge ecriture.base_acemo_reduite_8_tri (in=in1)
	 lect7.tab_passage_dep_reg;
	 by dep ;
	 if in1;
	 run;
/* cr�ation de base_acemo_reduite_10 par fusion de base_acemo_reduite_9 */
/*                                   et de la base ipc_regionaux  */
proc sort data=ecriture.base_acemo_reduite_9; by idregion annee trimestre;run;
proc sort data=ipcreg.ipc_regionaux; by idregion annee trimestre;run;
data ecriture.base_acemo_reduite_10;
merge ecriture.base_acemo_reduite_9 (in=in1)
	  ipcreg.ipc_regionaux;
	  by idregion annee trimestre;
	  if in1;
	  run;

/*proc contents data=ecriture.base_acemo_reduite_10;run;*/

/* v�rif */
data verif3;set ecriture.base_acemo_reduite_8 (where=(DEP=' '));run;/* 45 obs */
proc sort data=verif3 out= verif3b nodupkeys;by SIRET;run;

data verif2;set ecriture.base_acemo_reduite_9 (where=(DEP=' '));run;/* 45 obs */
proc sort data=verif2 out= verif22 nodupkeys;by SIRET;run;
data verif2b;set ecriture.base_acemo_reduite_9 (where=(idregion=.));run;/*1847 obs */
proc sort data=verif2b out= verif2b2 nodupkeys;by DEP;run;
data verif2c;set ecriture.base_acemo_reduite_9 (where=(idregion=. and DEP=' '));run;/* 45 obs */
data verif2d;set ecriture.base_acemo_reduite_9 (where=(idregion=. and DEP ne ' '));run;/*1802 obs */
data verif2e;set ecriture.base_acemo_reduite_9 (where=(idregion=. and DEP = '00'));run;/*69 obs */
data verif2f;set ecriture.base_acemo_reduite_9 (where=(idregion=. and DEP = '99'));run;/*1736 obs */

data verif5;set ipcreg.ipc_regionaux (where=(ipc_reg=.));run;/* 0 obs. */
data verif5b;set ipcreg.ipc_regionaux (where=(idregion=.));run;/* 0 obs. */
data verif5c;set ipcreg.ipc_regionaux (where=(idregion=93));run;/* 0 obs. */
data verif5d;set ipcreg.ipc_regionaux (where=(idregion=94));run;/* 0 obs. */
data verif5e;set ipcreg.ipc_regionaux (where=(idregion=92));run;/* 0 obs. */

data verif;set ecriture.base_acemo_reduite_10 (where=(DEP=' '));run;/* 45 obs */
data verif6;set ecriture.base_acemo_reduite_10 (where=(idregion=.));run;/* 1847 obs */
data verif6b;set verif6 (where=(DEP='99'));run;/* 1733 */
data verif6c;set verif6 (where=(DEP='00'));run;/* 69 */
data verif6d;set verif6 (where=(DEP=' '));run;/* 45 */
data verif7;set ecriture.base_acemo_reduite_10 (where=(idregion=. and DEP ne ' '));run;/*1802 obs */
data verif7b;set verif7 (where=(DEP='99'));run;/* 1733 */
data verif7c;set verif7 (where=(DEP='00'));run;/* 69 */
data verif4;set ecriture.base_acemo_reduite_10 (where=(ipc_reg=.));run;/* 255595 obs apr�s correction 93 en 92 : 9833obs*/
data verif4b;set verif4 (where=(idregion=.));run;/* 1847 obs */
data verif4b1;set verif4b (where=(dep=' '));run;/* 1847 obs */
data verif4b2;set verif4b (where=(dep='00'));run;/* 1847 obs */
data verif4b3;set verif4b (where=(dep='99'));run;/* 1847 obs */
data verif4b4;set verif4 (where=(idregion=94));run;/* 1847 obs */
data verif4c;set verif4 (where=(idregion ne .));run;/* 253 748 obs */
proc sort data=verif4 out= verif44 nodupkeys;by idregion annee trimestre;run;/* pas d'ipc_reg pour idregion =93 et 94 */
proc print data=verif44;var siret nomregion idregion dep nomdep ipc_reg annee trimestre;run;
/* verif des idregion non communs */
proc sort data=ecriture.base_acemo_reduite_10 out=verif8 nodupkeys;;by idregion;run; /*  */
proc sort data=ipcreg.ipc_regionaux out=verif8b nodupkeys;;by idregion;run; /*  */
data verif8c;set ecriture.base_acemo_reduite_10 (where=(idregion=93));run;/* 45 obs */
data verif8d;set ecriture.base_acemo_reduite_10 (where=(idregion=94));run;/* 45 obs */






/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/****************** DERNIERES BASES CREEES :                         *************************/
/******************              BASE_ACEMO_REDUITE_11               *************************/
/******************              4 571 627 obs et 68 variables       *************************/
/******************                                                  *************************/
/******************              BASE_ACEMO_REDUITE_12               *************************/
/****************** contenant les dur�es mais tenant compte des restrictions  ****************/
/******************              3 867 978 obs et 76 variables        ************************/
/* ST le 10/07/2007                                                                         **/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  ATTENTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/************************************ ST le 05/07/07 ****************************************/

/*** l'indicatrice RTT a �t� recr�ee dans un programme � part qui cr�e BASE_ACEMO_REDUITE_11 */
/*** A partir de BASE_ACEMO_REDUITE_11, on a cr�� les durees et la base finale est :         */
/* BASE_ACEMO_REDUITE_12. Cette base contient moins d'observations que  BASE_ACEMO_REDUITE_11*/
/* car elle prend en compte les restrictions : R_RETOUR ='3' and PREST1='O' and INDICABERHOR in (0,2)*/


/* ATTENTION : si INDIC_RTT et DUREE sont bonnes, refaire les bases reduites ci-dessous
/*  a partir de base_acemo_reduite_11 */
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!/
/*************************************************************************************************/
/* LA PARTIE DE PRGM QUI CREE BASE_ACEMO_REDUITE_11 EST RAPATRIEE ICI                            */                
/*************************************************************************************************/

/***************************************************************************/
/* NOUVELLE INDICATRICE DE RTT - CALCUL DU LAG_HORMENS                     */
/***************************************************************************/
data ecriture.base_acemo_reduite_11; set ecriture.base_acemo_reduite_10;
lsiret=lag(siret);
lcat=lag(cat);
lag_hormens=.;
delhormens=lag(hormens);
if siret=lsiret and cat=lcat then lag_hormens=delhormens;
INDIC_RTT=0;
IF (hormens le 152 and hormens ge 140) and (lag_hormens ge 165) then INDIC_RTT=1;
run;



proc contents data=ecriture.base_acemo_reduite_11;run;


/***************************************************************/
/* CREATION DE BASE_ACEMO_REDUITE_SALMENSE                     */
/* AVEC indicabermens in (0,2) and PREST1='O' and R_RETOUR='3' */
/* 3 839 408 obs.                                              */
/***************************************************************/
data ecriture.base_acemo_reduite_salmense;set ecriture.base_acemo_reduite_11
(where=(indicabermens in (0,2) and PREST1='O' and R_RETOUR='3'));run;
proc contents data=ecriture.base_acemo_reduite_salmense;run;

/***************************************************************/
/* CREATION DE BASE_ACEMO_REDUITE_SALHOR                       */
/* AVEC indicaberhor in (0,2) and PREST1='O' and R_RETOUR='3'  */
/* 3 861 978 obs.                                              */
/***************************************************************/
data ecriture.base_acemo_reduite_salhor;set ecriture.base_acemo_reduite_11
(where=(indicaberhor in (0,2) and PREST1='O' and R_RETOUR='3'));run;
proc contents data=ecriture.base_acemo_reduite_salhor;run;





/**********************************************************/
/* A RELANCER LE 25 AVRIL 2007 							  */
/**********************************************************/

/**********************************************************/
/**********************************************************/
/*   CREATION D'UNE BASE BASE_ENTREPRISES_REDUITE         */
/*   le 26 octobre 2006 JM et LB                          */ 
/*   ON REPART DE BASE_ACEMO_REDUITE                      */ 
/*   CAR BASE_ACEMO_REDUITE_7 NE CONTIENT QUE DES         */
/*   VARIABLES SUPPLEMENTAIRES                            */ 
/**********************************************************/
/**********************************************************/

/****************************************/
/*    Salaire par entreprise            */
/***************************************/
/* TH le 25 04 07 */
proc means data=ecriture.base_acemo_reduite
(where=(r_retour='3' and prest1='O' and indicabermens in (0,2) and indicabermens_new = 0)) noprint;
weight poids;
by date siret; var dlnsalmense /* isalm */;  output out=isalmtot2(drop=_type_ _freq_)
mean= isalmtot2; run;

* TH le 25 avril 2007; 
proc means data=ecriture.base_acemo_reduite
(where=(r_retour='3' and prest1='O' and indicabermens in (0,2) and indicabermens_new = 0 and CSP="OUV")) noprint;
weight poids;
by date siret; var dlnsalmense /* isalm */; output out=isalmouv2(drop=_type_ _freq_)
mean= isalmouv2; run;

/*************************************************/
/*  Verif agregation des salaires par entreprise */
/*************************************************/
proc sort data=ecriture.base_acemo_reduite nodupkeys out=A ; 
by date siret ;run;
/***************************************/
/*  Recalcul d'un PTOT2 avec val aber  */
/**************************************/
/*
data B;
merge isalmtot2 A;
by date siret;
keep date siret isalmtot2 ptot ;
run;
proc means data=B;
weight ptot;
by date ; var isalmtot2; output out=isalm_verif2(drop=_type_ _freq_) mean= moy; run;
*/
/*verif somme poids*/
/*
proc means data=B;
 var ptot; output out=verif(drop=_type_ _freq_) sum= moy; run;
*/
/***************************************/
/*  Recalcul d'un PTOT2 sans val aber  */
/**************************************/
proc means data=ecriture.base_acemo_reduite
(where=(r_retour='3' and prest1='O' and indicabermens in (0,2) and indicabermens_new = 0)) noprint;
by date siret; var poids; output out=ptot2(drop=_type_ _freq_) sum= ptot2; run;
proc sort data=isalmtot2 nodupkeys out=y2 ; 
by date siret ;run;

* TH le 25 avril 2007; 
proc sort data=isalmouv2 nodupkeys out=y3 ; 
by date siret ;run;

/* CREATION DE LA TABLE DES ENTREPRISES */
data ecriture.base_entreprises_reduite;
merge ptot2 (in=a) y2 y3; if a;
by date siret;
keep date siret isalmtot2 isalmouv2 ptot2 ;
run;
proc means data=ecriture.base_entreprises_reduite;
weight ptot2;
by date ; var isalmtot2; output out=isalmtot3(drop=_type_ _freq_)
mean= moy; run;

proc contents data=ecriture.base_entreprises_reduite;run;

/**********************************************************/
/*   CREATION D'UNE BASE BASE_ENTREPRISES_REDUITE_HOR     */
/*   le 20 NOVEMBRE 2006 JM et LB                         */ 
/**********************************************************/
/* avec ISALHTOT2 */
/* SUITE DEMANDE THOMAS */
/****************************************/
/*    Salaire par entreprise            */
/***************************************/
proc means data=ecriture.base_acemo_reduite
(where=(r_retour='3' and prest1='O' and indicaberhor in (0,2) /*and indicabermens_new = 0*/)) noprint;
weight poids;
by date siret; var dlnsalhor; output out=isalhtot2(drop=_type_ _freq_)
mean= isalhtot2; run;

* TH le 25 avril 2007; 
proc means data=ecriture.base_acemo_reduite
(where=(r_retour='3' and prest1='O' and indicaberhor in (0,2) /*and indicabermens_new = 0*/ and CSP="OUV")) noprint;
weight poids;
by date siret; var dlnsalhor; output out=isalhouv2(drop=_type_ _freq_)
mean= isalhouv2; run;

/*************************************************/
/*  Verif agregation des salaires par entreprise */
/*************************************************/
proc sort data=ecriture.base_acemo_reduite nodupkeys out=A ; 
by date siret ;run;
/***************************************/
/*  Recalcul d'un PTOT2 avec val aber  */
/**************************************/
/*
data B;
merge isalhtot2 A;
by date siret;
keep date siret isalhtot2 ptot ;
run;
proc means data=B;
weight ptot;
by date ; var isalhtot2; output out=isalh_verif2(drop=_type_ _freq_) mean= moy; run;
*/

/*verif somme poids*/

/*
proc means data=B;
 var ptot; output out=verif(drop=_type_ _freq_) sum= moy; run;
*/

/***************************************/
/*  Recalcul d'un PTOT2 sans val aber  */
/**************************************/
/* LB le 25 avril 07 */
proc means data=ecriture.base_acemo_reduite
(where=(r_retour='3' and prest1='O' and indicaberhor in (0,2) /*and indicabermens_new = 0*/)) noprint;
by date siret; var poids; output out=ptot2(drop=_type_ _freq_) sum= ptot2; run;
proc sort data=isalhtot2 nodupkeys out=y2 ; 
by date siret ;run;

* TH le 25 avril 2007; 
proc sort data=isalhouv2 nodupkeys out=y3 ; 
by date siret ;run;

/* CREATION DE LA TABLE DES ENTREPRISES */
data ecriture.base_entreprises_reduite_hor;
merge ptot2 (in=a) y2 y3; if a;
by date siret;
keep date siret isalhtot2 isalhouv2 ptot2 ;
run;
proc means data=ecriture.base_entreprises_reduite_hor;
weight ptot2;
by date ; var isalhtot2; output out=isalhtot3(drop=_type_ _freq_)
mean= moy; run;
proc contents data=ecriture.base_entreprises_reduite_hor;run;

/**********************************************************/
/*   CREATION D'UNE BASE BASE_ENTREPRISES_REDUITE_DEF     */
/*   le 20 NOVEMBRE 2006 JM et LB                         */ 
/* avec isalmtot2 et isalhtot2                            */
/**********************************************************/
/* fusion ecriture.base_entreprises_reduite et ecriture.base_entreprises_reduite_hor */

data ecriture.base_entreprises_reduite_def;
merge ecriture.base_entreprises_reduite ecriture.base_entreprises_reduite_hor;
by date siret;run;
proc contents data=ecriture.base_entreprises_reduite_def;run;






